System.Security.SecurityException from a .NET website deployed in Web Server

In some cases while you have uploaded the compiled and published release files of your ASPNETMVC web application or ASPNET Web Application in Godaddy or any other hosting provider, you might have encountered an error which states “System.Security.SecurityException: Request for the permission of type ‘System.Security.Permissions.ReflectionPermission, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089’ failed.” might be because partial or medium trust is not supported for Microsoft.Owin.Host.SystemWeb package since this package helps in running OWIN middlewares on IIS integrated pipeline and the assembly does reflection to detect and load OWIN Startup class.

This kind of issue will occur when you build an MVC5 application with OWIN Startup class included having OWIN package installed. Below is the typical way the application error shown when you make <customErrors mode = “Off” /> in Web.Config file.

image

In order to resolve this issue you need to provide <trust level = “Full”/> under System.Web  section in Web.Config file

<system.web>
  <authentication mode="None" />
  <compilation debug="true" targetFramework="4.5" />
  <httpRuntime targetFramework="4.5" />
  <customErrors mode="Off"/>
  <trust level="Full" />
</system.web>

Hope this helps to my fellow developers if you are facing the same scenario somewhere

5 thoughts on “System.Security.SecurityException from a .NET website deployed in Web Server

  1. Oh my goodness! Impressive article dude! Thanks, However
    I am experiencing problems with your RSS. I don’t understand why I cannot join it.
    Is there anybody getting identical RSS problems?
    Anyone who knows the answer will you kindly respond? Thanx!!

  2. After checking out a number of the articles on your web site, I truly like your way of blogging.
    I saved as a favorite it to my bookmark site list and
    will be checking back soon. Please visit my web site as well and let me know your opinion.

Leave a Reply

%d bloggers like this: