Christopher Bennage

Sponsors

The Lounge

Wicked Cool Jobs

Syndication

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 imagehelp@codebetter.com
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

[Advertisement]

Comments

Jim Hertshire wrote re: Shared Hosting & The Bleeding Edge
on 09-25-2008 1:54 PM
Good job it was your friend. I hope he stays that way after you made such a fundamental error.
Christopher Bennage wrote re: Shared Hosting & The Bleeding Edge
on 09-25-2008 2:00 PM

Um, thanks...

ASP.NET MVC Archived Buzz, Page 1 wrote ASP.NET MVC Archived Buzz, Page 1
on 09-25-2008 3:02 PM

Pingback from  ASP.NET MVC Archived Buzz, Page 1

Bill Pierce wrote re: Shared Hosting & The Bleeding Edge
on 09-25-2008 4:33 PM
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
Andrew Tobin wrote re: Shared Hosting & The Bleeding Edge
on 09-25-2008 6:39 PM
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.
DotNetKicks.com wrote Shared Hosting and the Bleeding Edge
on 09-25-2008 9:43 PM

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

Reflective Perspective - Chris Alcock » The Morning Brew #188 wrote Reflective Perspective - Chris Alcock » The Morning Brew #188
on 09-26-2008 3:26 AM

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

2008 September 25 - Links for today « My (almost) Daily Links wrote 2008 September 25 - Links for today « My (almost) Daily Links
on 09-26-2008 4:57 AM

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

Andy Scott wrote re: Shared Hosting & The Bleeding Edge
on 09-26-2008 7:53 AM
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
Code Monkey Labs wrote Weekly Web Nuggets #31
on 09-27-2008 11:46 PM

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

Code Monkey Labs wrote Weekly Web Nuggets #31
on 02-22-2009 10:45 PM

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

About The CodeBetter.Com Blog Network
CodeBetter.Com FAQ

Our Mission

Advertisers should contact Brendan

Subscribe
Google Reader or Homepage

del.icio.us CodeBetter.com Latest Items
Add to My Yahoo!
Subscribe with Bloglines
Subscribe in NewsGator Online
Subscribe with myFeedster
Add to My AOL
Furl CodeBetter.com Latest Items
Subscribe in Rojo

Member Projects
DimeCasts.Net - Derik Whittaker

Friends of Devlicio.us
Red-Gate Tools For SQL and .NET

NDepend

SlickEdit
 
SmartInspect .NET Logging
NGEDIT: ViEmu and Codekana
LiteAccounting.Com
DevExpress
Fixx
NHibernate Profiler
Unfuddle
Balsamiq Mockups
Scrumy
JetBrains - ReSharper
<-- NEW Friend!

 



Site Copyright © 2007 CodeBetter.Com
Content Copyright Individual Bloggers

 

Community Server (Commercial Edition)

CodeBetter.Com