2

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.

Community
  • 1
  • 1
Daniel.S
  • 913
  • 8
  • 8
  • 1
    Is there any chance we could see the rest of the call stack? That would let us see which library is requesting Reflection Permission - because I don't think the default ASP.NET MVC stack requires that - things like StructureMap or NHibernate however may do: http://stackoverflow.com/questions/784666/how-do-you-deploy-an-asp-net-mvc-site-using-structuremap-2-5-3-in-a-medium-trust – Zhaph - Ben Duguid May 14 '09 at 11:06
  • I'll review it, but I'm certainly not using StructureMap or NHibernat. This was a clean install of VS 2008 and NET MVC 1.0., with a clean MVC project. – Daniel.S May 18 '09 at 02:17

3 Answers3

3

The current version of ASP.NET MVC only support <trust level="Full" /> - refer this answer

Community
  • 1
  • 1
Ankush Guhe
  • 797
  • 4
  • 17
1

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
  • 2,600
  • 2
  • 24
  • 26
  • 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 May 14 '09 at 05:15
0

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
  • 12,343
  • 9
  • 37
  • 38
  • 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 May 14 '09 at 09:45
  • 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 May 14 '09 at 17:46
  • 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 May 18 '09 at 02:15
  • I can't believe that works I have godaddy.com shared hosting as well by putting in the web.config I was able to run my MVC5 app. – Aaron Oct 04 '14 at 07:52