C# .NET - How do I find out what trust level is required for a given .NET function call?

Asked By Patrick Skelton on 30-Jan-13 02:49 PM
Hi,

I am writing an ASP.NET website. On my local machine, it runs under Full Trust.  My hosting service applies Medium Trust (I believe) with a couple of modifications.  How can I be sure not to call a .NET library function that will throw a security exception on my remote host?  Surely, this is in the MSDN documentation, but I don't seem to be able to find it.

Any help would be very much appreciated.

Kind wishes, Patrick
Robbe Morris replied to Patrick Skelton on 30-Jan-13 05:38 PM
A typical ASP.NET application isn't going to run into these sorts of issues.  If you stay away from COM dependencies and accessing things like DirectoryServices, you should be just fine.  If you have some particular functionality to ask about, I might be able to help.
Patrick Skelton replied to Robbe Morris on 31-Jan-13 07:36 AM
Hi, Robbe,

Thank you for the reply.

If I remember correctly from the last time I came across this problem, it was Assembly.GetExecutingAssembly()
 that caused the security exception with my hosting provider.  All I wanted to get from this was the version, a harmless text string, but of course this call doesn't know that.

I could be wrong.  I haven't run the code on the live server yet, but as I say, I do remember having problems with this before.

Kind wishes, Patrick
Robbe Morris replied to Patrick Skelton on 31-Jan-13 08:01 AM
Why would you need this in your own ASP.NET application?
Patrick Skelton replied to Robbe Morris on 31-Jan-13 08:29 AM
Simply to display, so I can easily check the version of code on the live site - a bit like the About window in most desktop applications.

- Patrick
Robbe Morris replied to Patrick Skelton on 31-Jan-13 08:35 AM
You'll probably want to start putting that in the web.config.  Hosting companies are going to prevent you from obtaining certain "system like" data so that you cannot spy on other web sites hosted on the same server.
Patrick Skelton replied to Robbe Morris on 31-Jan-13 09:30 AM
Hi, Robbe,

Funnily enough, I was going to do that, but I (perhaps mistakenly) thought I should be doing it the 'proper' way.

You learn something every day (and I generally forget two things).

Thanks.

~ Patrick
Robbe Morris replied to Patrick Skelton on 31-Jan-13 10:01 AM
You see tactic of getting dynamically mostly in non web apps such as windows forms or WPF.  It is used by ClickOnce and various other software update strategies.