3

I Have an ASP.NET MVC 5 application that works fine on the development machine. I published it and transferred the files online, and it generates the following error:

Security 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 failed.

Source Error:

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

Stack Trace:


[SecurityException: Request failed.]
   System.Security.CodeAccessSecurityEngine.ThrowSecurityException(RuntimeAssembly asm, PermissionSet granted, PermissionSet refused, RuntimeMethodHandleInternal rmh, SecurityAction action, Object demand, IPermission permThatFailed) +165
   System.Security.CodeAccessSecurityEngine.ThrowSecurityException(Object assemblyOrString, PermissionSet granted, PermissionSet refused, RuntimeMethodHandleInternal rmh, SecurityAction action, Object demand, IPermission permThatFailed) +100
   System.Security.CodeAccessSecurityEngine.CheckSetHelper(PermissionSet grants, PermissionSet refused, PermissionSet demands, RuntimeMethodHandleInternal rmh, Object assemblyOrString, SecurityAction action, Boolean throwException) +272
   System.Security.CodeAccessSecurityEngine.CheckSetHelper(CompressedStack cs, PermissionSet grants, PermissionSet refused, PermissionSet demands, RuntimeMethodHandleInternal rmh, RuntimeAssembly asm, SecurityAction action) +55
   System.RuntimeTypeHandle.GetTypeByName(String name, Boolean throwOnError, Boolean ignoreCase, Boolean reflectionOnly, StackCrawlMarkHandle stackMark, IntPtr pPrivHostBinder, Boolean loadTypeFromPartialName, ObjectHandleOnStack type) +0
   System.RuntimeTypeHandle.GetTypeByName(String name, Boolean throwOnError, Boolean ignoreCase, Boolean reflectionOnly, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean loadTypeFromPartialName) +70
   System.RuntimeType.GetType(String typeName, Boolean throwOnError, Boolean ignoreCase, Boolean reflectionOnly, StackCrawlMark& stackMark) +39
   System.Type.GetType(String typeName) +50
   System.CodeDom.Compiler.CompilerInfo.get_IsCodeDomProviderTypeValid() +10
   System.Web.Compilation.CompilationUtil.GetRecompilationHash(CompilationSection ps) +2090
   System.Web.Configuration.CompilationSection.get_RecompilationHash() +107
   System.Web.Compilation.BuildManager.CheckTopLevelFilesUpToDateInternal(Int64 cachedHash) +465
   System.Web.Compilation.BuildManager.CheckTopLevelFilesUpToDate(Int64 cachedHash) +51
   System.Web.Compilation.BuildManager.ExecutePreAppStart() +132
   System.Web.Hosting.HostingEnvironment.Initialize(ApplicationManager appManager, IApplicationHost appHost, IConfigMapPathFactory configMapPathFactory, HostingEnvironmentParameters hostingParameters, PolicyLevel policyLevel, Exception appDomainCreationException) +521

My hosting provides me with an ASP.NET Settings panel.

My settings are as follows:

Framework version: 4.0.30319.17929
Default webpage language: C#
CAS trust level: FULL

Can anyone guide me as to what is the problem. Is it the app or the hosting?

2
  • 1
    It could be a combination of both actually. When you say "publish" are you publishing to Azure or some other solution? Do you have access to the app pool under which app is configured? Check the identity of the process that is running that particular app pool. Commented Oct 30, 2016 at 5:33
  • It's a third party hosting. Not azure. I don't have access to app pool config Commented Oct 30, 2016 at 10:09

1 Answer 1

6

Most of hosting provider offer FULL Trust hosting now. MVC does not accept partial trust.

<system.web>
     <trust level="Full" />
   </system.web>

If this does not work You should contact your hosting service provider if you don’t have access to the server.

What we do is run the following in our dev.

<system.web>
  <trust level="Medium"/>
</system.web>

Changing the trust level makes the staging environment fail with the same error shown on the shared host so you can correct your code to comply with your host. If you’re deploying to a medium trust hosting environment you’d be wise to set the trust level to Medium up front to save time and energy down the road.

Here is a link

Sign up to request clarification or add additional context in comments.

3 Comments

Is this trust level different than a CAS trust Level? Because I have access to that config and I put it at full.
Ah ok i see whats going on. CAS policy (Code Access Security) levels mainly come from older systems, No really used any more. here is a link to help you get going on this. msdn.microsoft.com/en-us/library/dd984947.aspx

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.