Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What are the most common, typical things to AVOID coding into my ASP.NET app in order for it to run under Medium Trust on a shared host?

What are the things that Medium Trust stops you from doing? For example, I've already learned that Medium Trust stops you from using System.IO.Path.GetTempPath(). What other things like that?

like image 206
Corey Trager Avatar asked Nov 09 '08 00:11

Corey Trager


2 Answers

Here's how to learn about and resolve trust issues.

1) Search your Windows\Microsoft.NET\Framework[YOUR VERSION]\CONFIG folders for the files:

  • web.config (this is the root config file)
  • web_mediumtrust.config
  • web_hightrust.config

2) Change the web.config to say

<trust level="Medium" originUrl="" />

3) Try your ASP.NET app. Mine failed with a permission error.

4) Diff the web_mediumtrust.config and web_hightrust.config in a diff tool, like WinMerge.

5) Copy settings from the high to the medium one at a time and see how they affect your app. In my case, the error message referred to ConfigurationPermission, so it was easy to diagnose.

If you can pin down the precise lines in the web_mediumtrust.config file that are blocking you, then maybe you can share that with your hosting company and have a better chance of working things out.

More documentation here:
http://msdn.microsoft.com/en-us/library/aa302425.aspx

@Oli, my app IS hosted at GoDaddy and I had to do some workarounds in code when I started using Lucene.NET. I had to modify the Lucene.NET source code to not use GetTempPath and System.IO.FileInfo.

like image 84
Corey Trager Avatar answered Oct 14 '22 03:10

Corey Trager


Who can be sure? That's why you should develop with a trust level of medium set in your web.config.

 <trust level="Full|High|Medium|Low|Minimal" />
like image 27
Shawn Avatar answered Oct 14 '22 02:10

Shawn