Images in this post missing? We recently lost them in a site migration. We're working to restore these as you read this. Should you need an image in an emergency, please contact us at
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.

Posted 09-25-2008 11:58 AM by Christopher Bennage


About The CodeBetter.Com Blog Network
CodeBetter.Com FAQ

Our Mission

Advertisers should contact Brendan

Google Reader or Homepage Latest Items
Add to My Yahoo!
Subscribe with Bloglines
Subscribe in NewsGator Online
Subscribe with myFeedster
Add to My AOL
Furl Latest Items
Subscribe in Rojo

Member Projects
DimeCasts.Net - Derik Whittaker

Friends of
Red-Gate Tools For SQL and .NET


SmartInspect .NET Logging
NGEDIT: ViEmu and Codekana
NHibernate Profiler
Balsamiq Mockups
JetBrains - ReSharper
Web Sequence Diagrams
Ducksboard<-- NEW Friend!


Site Copyright © 2007 CodeBetter.Com
Content Copyright Individual Bloggers


Community Server (Commercial Edition)