I have been moving hosting provider to godaddy. Easily the biggest hurdle to overcome has been medium trust. Enforcing medium trust policy is a common approach in shared hosting environments the intention being to stop applications from trampling on each other. The existing site were a mixture of web applications and static pages that used a mix of technologies.

Static pages

Obviously no real problem moving these, though they were redesigned on the way.

Blog – BlogEngine.NET

Part of the main reason for me to move was to get away from Wordpress and move to Blogengine.NET, Blogengine.NET seemed to pretty much work fine except that it ran very slowly until I made the following change to the web.config, though I don’t think that this had anything to do with medium trust.

      <urlcompression dostaticcompression="false" dodynamiccompression="false" />

Books – SQL Server CE4 and NHibernate

This used a NHibernate repository pattern over a SQLite DB. I could not find any way of getting SQLite to work in a medium trust environment. Whereas one of the big ticket items in CE4 is its ability to run in Medium Trust. It turns out that it was reasonably easy to migrate from SQLite to CE – I had scripted the SQLite DB so I just had to tweak the script. I made use of the rather excellent SQLCEToolbox.

NHibernate really did do its job in that the new DB worked without any code change – however I did find that the performance of CE4 was much slower than SQLite so in the end I had to tweak the way I was retrieving information and ended up modifying my HQL. The only slightly complex part is that all the DLLs for CE4 must be copied to the local BIN folder on the web site – the easiest method is to Add Deployable Dependencies

NHibernate was a different matter – as I said it worked fine locally when I swapped databases however it would not work in medium trust. It turns out that others had run into the same problems and that the root of the problem was in the lazy generation of proxies, and also that the DLLs need to be marked to AllowPartiallyTrustedCallers. There is a project to pre generate proxies but I could not get it to work.

Then I found this article – its genius Option 4 – use somebody else’s files. It worked a treat. I just referenced the borrowed DLLs and everything was fine

I did need to move my configuration into my web.config – did this for a lot of things. The config sections need the requirePermission attribute setting to false, as you can see I also did this for log4net, there probably is a way to apply this to an external file but in the end I just put it all in one file for a quiet life.

    <section name="hibernate-configuration" requirePermission="false" type="NHibernate.Cfg.ConfigurationSectionHandler, NHibernate"/>
    <section name="log4net" requirePermission="false" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net"/>

Worldolio – log4net and System.Runtime.Caching

Worldolio is an shareware product I was also moving it to the new host. It made use of EnterpriseLibrary for caching and logging. I have liked EnterpriseLibrary for a long time but I could not get it to work in a medium host environment. In the and it appeared that the instructions presumed that I could redefine Medium trust to add extra permissions – I think that in a real shared hosting environment this would not be the case.

So I decided to bite the bullet and replace EnterpriseLibrary logging with log4net and caching with System.Runtime.Caching Pretty much the only thing that needed doing for log4net was adding requirePermission into the web.config and the System.Runtime.Caching worked fine from the word go.