Devlico.Us
CodeBetter.Com
RSS 2.0 via Feedburner
           Do you Twitter? Follow us @devlicious

Christopher Bennage

Our WPF book is now available!
follow @bennage on Twitter!


Shared Hosting & The Bleeding Edge

So we've been working on a web project for a friend's startup company (I don't like doing work for my friends, but that's a different matter). Since he has no technological preference and since we are such bleeding edge kinda guys (the Achilles' Heel of ALT.NET?), we decided to build the site with the following:

Castle and NHibernate (as you likely know) are mature products. So in keeping with our bleeding theme, we decided to use the trunk for these instead of the most recent release.

Despite all the blood, the development process was pretty smooth. I had a minor learning curve with MVC and a slightly less minor curve with some of the other bits, but all in all, it went well. (I am omitting a lengthy struggle writing a query because it is embarrassing how my SQL query writing skills have atrophied.)

Ok, well, the time to deploy to the production site comes. Remember I said that this was a friend's startup and there is little money to go around, so the production site is going be hosted at CrystalTech. I deploy the site, and -- nothing. It doesn't work in the shared hosting environment.

We're not used to having our applications run in a shared environment; most of our clients have dedicated hardware. If I had spent any amount of time thinking about it, I would have realized the forthcoming pain.

Unfortunately, I will not be able to present you with a step-by-step way to make the pieces fit, the pain has blurred my memory. However, I will give you a general outline that I believe you will find helpful.

Windows 2008, IIS 7, and Routing

Most shared hosting environments are not running on Windows 2008 and that means no IIS 7. If you are using routing with MVC to get your Rails-style urls (and who isn't?), routing is not going to work without IIS7. You can still get your MVC app to run, but  you have to call the view explicitly (something like \root\views\home\index.aspx).

I didn't really think about this because the web server built-in to Visual Studio handles the routing correctly. (Even though I've run into a similar problem using MonoRail years ago).

CrystalTech (at the time of writing) only has one server running IIS 7 and only one plan available for that server. I didn't think about this when my buddy signed up for the account, and I had to ask them to relocated the site to the 2008 server.

Drew suggested that I ask the host to do a wildcard mapping instead of moving the site over to IIS 7. This would work, but CrystalTech won't to do it. I had actually tried to get them to do this a while back when I first started learning MonoRail.

Partial Trust

Shared hosting environment have to restrict security. If not, you could write your application to do bad things to their server. Limited trust can prevent you from using lots nifty tricks that you may be used to. For example, application running under Medium Trust cannot use reflection. Luckily, many hosts don't lock you down that tight.

The real problem is that by default strongly named assemblies cannot be called by assemblies executing under less than Full Trust. For example, the Castle assemblies are strongly-named and thus they are not callable by your application in most typical shared environments.

The solution, if you have access to the source, is to use AllowPartiallyTrustedCallersAttribute. Just slap that bad boy into your AssemblyInfo.cs and your strongly named assembly can then be called.

Fortunately, Castle makes this easy. You execute the build script with something like this:

nant -t:net-2.0 -D:assembly.allow-partially-trusted-callers=true release

I believe NHibernate has the attribute by default, but any other assembly that is strongly-named will need this attribute, and then you will want to recompile all the dependencies after adding the attribute.

The Nutshell

If you have to use a shared hosting environment, talk to the host. Tell them what you are planning on doing. Secondly, visit the forums for the host and search them to see if someone is doing what you plan to do.



Comments

Christopher Bennage said:

Um, thanks...

# September 25, 2008 2:00 PM

ASP.NET MVC Archived Buzz, Page 1 said:

Pingback from  ASP.NET MVC Archived Buzz, Page 1

# September 25, 2008 3:02 PM

Bill Pierce said:

Hey Christopher, If you are trying to use lazy loading with NHibernate in Medium Trust you should check out NHibernate ProxyGenerators. http://www.nhforge.org/blogs/nhibernate/archive/2008/09/22/introducing-nhibernate-proxygenerators.aspx -Bill
# September 25, 2008 4:33 PM

Andrew Tobin said:

Hey Chris, I ran into the same thing on just a play around dev project. I was really looking forward to just deploying MVC and forgetting about it, but the 404's attacked and I ended up having to have http://host/controller.aspx/action/id/ It really makes it look awful having that aspx in there these days, and I'm guessing it's not good for SEO. It's a shame that there isn't more information just widely available on some parts of ASP .NET MVC yet, I had to do a lot of searching and investigation through the forums for things like using namespaces in routing, when you'd think they'd be publishing more videos or blog posts or howto's to get as much out there. I guess the guys are only human though and they can work on educating us about the system, or the system, at least until it's deployed. I do hope the story on shared hosting gets better, because a lot of the guys like Haack and Hanselman can afford Virtual Server hosting, but for my small experiments I sure can not.
# September 25, 2008 6:39 PM

DotNetKicks.com said:

You've been kicked (a good thing) - Trackback from DotNetKicks.com

# September 25, 2008 9:43 PM

Reflective Perspective - Chris Alcock » The Morning Brew #188 said:

Pingback from  Reflective Perspective - Chris Alcock  » The Morning Brew #188

# September 26, 2008 3:26 AM

2008 September 25 - Links for today « My (almost) Daily Links said:

Pingback from  2008 September 25 - Links for today « My (almost) Daily Links

# September 26, 2008 4:57 AM

Andy Scott said:

Yeah, you have used LLBLGen Pro for your DB access layer. So much better than nHibernate I have found and its really relatively very cheap. Other than that hope it went well! Andy
# September 26, 2008 7:53 AM

Code Monkey Labs said:

General Commented-Out Code & Broken Windows : Jan Van Ryswyck says what everyone is thinking – commented code introduces a lot of mess into your code. There’s a reason we use version control systems…just delete that code! I Love FirstOrDefault : Chris

# September 27, 2008 11:46 PM

Leave a Comment

(required)  
(optional)
(required)  

Enter the numbers above:
Add

About Christopher Bennage

Christopher is a software developer and consultant at Blue Spire Consulting, a company he co-founded with Rob Eisenberg in 2006. He is a Christian, a marginal musician, and an armchair philosopher. His interests include programming, liberal education, science, truth, beauty, and a number of deceased British authors (C. S. Lewis, G. K. Chesterton, and most recently Owen Barfield.) He lives in Tallahassee, FL with his wife and three children and still prefers to play as the Night Elves in WarCraft 3. Check out Devlicio.us!

Our Sponsors

Red-Gate!