How to Run a Website in Partial Trust

Nearly all our websites are hosted up on WebCentral. WebCentral operate all their websites under a partial (hosted) trust environment.

Internally we develop all our sites using this partial trust setup as it just causes too many headaches to develop in full trust and then try to retrofit everything to work under partial trust.

We originally received instructions on how to setup a machine to run in partial trust, but it involved editing config files located under the C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\CONFIG directory. While this is fine, if I wanted to test something quick and simple (and didn't care about partial trust), I'd have to rename files, restart IIS, close Cassini... blah blah blah... too hard..

A little while ago I discovered how to run just a site as partial trust. It involves putting the hostedtrust.config file in the same directory as the web.config file. This works well for us, as it means we can add all the files we require to a project, which are all then added to SourceSafe. When we get the latest version, we also get all required files to run in partial trust.


We were given the hosted trust setup from WebCentral as they dictate.

Copy this file into the root directory of your website.


In your web.config file add the following into the "system.web" configuration section.

<!-- **************************************************** -->
    <trustLevel name="Hosted2" policyFile="web_hostedtrust2.config"></trustLevel>
<!-- Comment out line below to run in FULL TRUST -->
<trust level="Hosted2" originUrl="" />

<!-- **************************************************** -->

Below is a screen shot of what my web.config file looks like.


If you ever need to run the site in full trust to test something out, just comment out the "trust" element.

What libraries I use (and don't use)

In my next post I'll list out the libraries I use in Partial Trust... and the one's I don't use and why.

I've had pretty good success getting sites working that need server-side image manipulation, ZIP creation and PDF creation / manipulation.

No Comments