views:

680

answers:

2

Hi, just trying to set up my development environment for ASP.NET MVC, have started a blank ASP.NET MVC project, and have placed the following in my web.config: <trust level="Medium" originUrl=""/>

Running the project then results in the following exception:

Description: The application attempted to perform an operation not allowed by the security policy. To grant this application the required permission please contact your system administrator or change the application's trust level in the configuration file.

Exception Details: System.Security.SecurityException: Request for the permission of type 'System.Security.Permissions.ReflectionPermission, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed.

If possible, I want to develop my app for medium trust, as I don't have a choice where it will be hosted, and the possibility exists that there may be some sort of restrictions with the trust levels.

+1  A: 

I can't reproduce this exception on my machine. You should be able to bin deploy ASP.Net MVC in medium trust. I have successfully done it on my host and godaddy. Are you using MVC 1.0? Have you changed or added restrictions to the Medium trust settings, possibly in an inherited web.config or machine.config file?

Ben Robbins
Thanks for the reply, Ben.I haven't changed anything over the defaults, MVC 1.0. I'm getting the exception when running the VS web server. I haven't tried it under IIS yet.
Daniel.S
A: 

I had a similar error for my website. It worked fine on my localmachine but would throw a permission error on my webhost. I actually just tried setting my web.config to...

<trust level="Full" />

and it worked fine for me. I didn't think it would work but it did.

codette
Codette, I'm forcing my app to work at Medium trust as I want to use that as a target for my development. That way my app will work on restrictive hosting environments.
Daniel.S
Well, depending on what you want to do from your website that might not be possible. For example, in my website I am using the HttpWebRequest object and I couldn't even create it without using "full" trust level on my webhost.
codette
It seems that way..NET MVC makes heavy use of reflection, which requires more than medium trust.It turns out that the platform I'm going to be hosting on is most likely running in full trust anyway. There's some good info here:http://mvchosting.asphostcentral.com/post/ASPHostCentralcom-ASPNET-MVC-Hosting-with-Full-Trust-Setting.aspx
Daniel.S