Common Shared Hosting Gotchas For .Net Apps
Hosting, particularly shared hosting plans, can sometimes cause unforeseen issues with application particularly those that are not off the shelf or have special requirements. This guide explains some of the common problems that can occur on certain hosting plans and what you can do to get around them.

Shared Hosting Gotchas For ASP.NET Sites

Hosting, particularly shared hosting plans, can sometimes cause unforeseen issues with application particularly those that are not off the shelf or have special requirements.  This guide explains some of the common problems that can occur on certain hostign plans and what you can do to get around them.

Custom Binaries - Trust Level

I had a problem with running some code which was connecting to a cloud based database service, using a c# driver for MongoDB databases.  Whilst developing the application on the test environment everything worked fine, but once uploaded to the shared hosting environment the application wouldn't run correctly.  You might see an error like this [SecurityException: That assembly does not allow partially trusted callers.]

The problem turned out to be that the shared hosting provider I was using (Go Daddy) were only running .net applications in medium trust level, which is not normally enough to run custom binaries. Shared hosting plans often set a strict policy on trust level as this could present a security risk if improperly managed.  I have successfully run the same application using mochahost who run all of their shared windows asp.net hosting plans in full trust level.

If you are planning on choosing a hosting provider for running .net and you run custom binaries, you should check first what trust level the server runs.

GoDaddy - Medium Trust

MochaHost - Full Trust

Custom Errors Not Showing

Most shared .net hosting accounts will not show errors by default.  This is a very good thing as you never want to reveal the details of errors to the world by default and present a major security risk if left enabled - however for the purposes of debugging it is OK to enable custom errors providing you re-enable them once you have completed your debugging.  Fortunately this is easily changed with a web.config file amendment in the system.web branch.

        <customErrors mode="Off">

        </customErrors>

Asp.Net routing not working on Shared Hosting

Routing is a great feature in asp.net 4.0 that allows you to control and setup seo friendly urls very easily from your global.asax file.  It should work out of the box without any changes to the web.config. Unfortunately this can sometimes not work with shared hosting as the static file handlers are set to take precedence.  Fortunately you can change this behaviour with a simple addition to the web.config file in the system.web server section

    <system.webServer>

        <modules runAllManagedModulesForAllRequests="true"></modules>

    </system.webServer>

File Permissions Preventing Writes

File permissions are usually read only by default on Shared hosting and this can often cause issues with anything that writes a log file for example, or generates a sitemap.xml file.  Most popular shared hosting providers will offer a way to enable write access from within their control panel and its simply a case of enabling this.

.Net Versions

ASP.NET will soon reach version 4.5, and previously release versions are 1.1, 2.0, 3.0, 3.5 and 4.0.  Keep in mind that asp.net 1.1 is usually not compatible with 2.0 and above, so check carefully that your hosting provider supports that version if you know you need it.  Similarly asp.net 4.0 offers backwards compatibility so run that if you can.  Keep in mind that by default in my experience most shared hosting companies will default their .net version to 2.0 and you will need to log-in to your hosts control panel to change the .net version if you need to.

Also don't assume that the hosting provider will support the latest version immediately, they can take some time to test and roll out a new version.  For example GoDaddy took around 6 months to offer ASP.NET 4.0 on their shared hosting platform after it was officially released. Most shared hosts will provide a feature list - check it supports the .net version you require before signing up.

MVC2 doesnt work on shared hosting

Shared hosting doesn't always work our of the box for what should be basic features.  However there is an easy way to get this to work - in your web project simply include the system.web.routing and system.web.mvc in your BIN directory.  You can make sure that the dll files are copied into the BIN folder by setting the "copy local" property to true on the dll reference within visual web developer / visual studio and then building your application.

Add Comment
Your Name
Your Comment
Your Email Address
Your Website Address
Add Comment
Sponsors