3

I have just written an MVC application and got it working in my lab. Now that I've deployed it to GoDaddy, I am getting the following error.

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) +284 System.Security.CodeAccessSecurityEngine.CheckSetHelper(CompressedStack cs, PermissionSet grants, PermissionSet refused, PermissionSet demands, RuntimeMethodHandleInternal rmh, RuntimeAssembly asm, SecurityAction action) +70 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) +40 System.Type.GetType(String typeName) +30 System.CodeDom.Compiler.CompilerInfo.get_IsCodeDomProviderTypeValid() +12 System.Web.Compilation.CompilationUtil.GetRecompilationHash(CompilationSection ps) +2175 System.Web.Configuration.CompilationSection.get_RecompilationHash() +96 System.Web.Compilation.BuildManager.CheckTopLevelFilesUpToDateInternal(Int64 cachedHash) +458 System.Web.Compilation.BuildManager.CheckTopLevelFilesUpToDate(Int64 cachedHash) +51 System.Web.Compilation.BuildManager.ExecutePreAppStart() +135 System.Web.Hosting.HostingEnvironment.Initialize(ApplicationManager appManager, IApplicationHost appHost, IConfigMapPathFactory configMapPathFactory, HostingEnvironmentParameters hostingParameters, PolicyLevel policyLevel, Exception appDomainCreationException) +531

I wondered about my database connection string, although the error doesn't seem to suggest any issue with the database.

So my real question is: How does one go about troubleshooting this. The messages don't really seem to help at all. What could be a next step?

Jonathan Wood
  • 65,341
  • 71
  • 269
  • 466
  • Are you using MVC-5? –  Jul 10 '16 at 23:32
  • @StephenMuecke: I just upgraded to the latest version of Visual Studio, so I'm using whatever version is the newest. – Jonathan Wood Jul 11 '16 at 14:50
  • 1
    I assume that would then be MVC-5. I don't know anything about GoDaddy hosting and what trust levels they support, but it could be related to the fact that MVC-5 no longer supports Medium trust (refer [this answer](http://stackoverflow.com/questions/25347092/deploying-asp-net-mvc-project/25354496#25354496)) –  Jul 11 '16 at 22:39

2 Answers2

4

This appears to be an issue with a mismatch between the version of .NET I'm using to build my app and the one provided on the host.

Thank you Microsoft for another error message that seems to tell me nothing about what the underlying issue is.

Jonathan Wood
  • 65,341
  • 71
  • 269
  • 466
2

It seems like the problem is the "Trust level". You need to specify which trustlevel you require in your web.config for your site. The problem though is that GoDaddy might not allow the trust level that your site requires. One of the trust levels allows/disallows e.g. reflection(e.g. IoC containers use reflection or AutoMapper).

The trust level thing is something Microsoft has stated that they do not support anymore, so any bugfixes etc that makes it unsecure is no longer fixed. So one solution might be to find another webhost is the change to the web.config doesn't fix your problem.

Example config:

<system.web>
  <securityPolicy>
    <trustLevel name="Full" policyFile="internal"/>
  </securityPolicy>
</system.web>
Hyperdingo
  • 271
  • 2
  • 6
  • Looked a bit more into it and found this article on GoDaddy: https://en.godaddy.com/help/what-trust-level-can-i-use-when-running-aspnet-2531 – Hyperdingo Jul 10 '16 at 19:24
  • When I go into the settings, it says CAS trust level is set to Full. So to the extent I understood it, that doesn't seem to be the issue. – Jonathan Wood Jul 10 '16 at 19:46
  • My bad, Ive been looking into this for my own causes previously and was certain it was the problem.. This article says it might also be due to the site not being under its own application pool. Is that something you got access to check? https://support.microsoft.com/en-us/kb/555466 If it still doesnt work I can't help, sorry. – Hyperdingo Jul 10 '16 at 20:24