托管 ASP.NET MVC 应用程序:安全异常

pro*_*mar 3 c# asp.net-mvc web-hosting shared-hosting asp.net-mvc-5

我有一个 ASP.NET MVC 5 应用程序,可以在开发计算机上正常运行。我发布它并在线传输文件,它生成以下错误:

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
Run Code Online (Sandbox Code Playgroud)

我的主机为我提供了 ASP.NET 设置面板。

我的设置如下:

Framework version: 4.0.30319.17929
Default webpage language: C#
CAS trust level: FULL
Run Code Online (Sandbox Code Playgroud)

谁能指导我到底是什么问题。是应用程序还是托管?

poo*_*pro 6

大多数托管提供商现在都提供完全信任托管。MVC 不接受部分信任。

\n\n
<system.web>\n     <trust level="Full" />\n   </system.web>\n
Run Code Online (Sandbox Code Playgroud)\n\n

如果这不起作用 如果您无权访问服务器,则应联系您的托管服务提供商。

\n\n

我们所做的就是在我们的开发中运行以下命令。

\n\n
<system.web>\n  <trust level="Medium"/>\n</system.web>\n
Run Code Online (Sandbox Code Playgroud)\n\n

更改信任级别会使暂存环境失败,并出现共享主机上显示的相同错误,因此您可以更正代码以符合您的主机的要求。\n如果您\xe2\x80\x99 正在部署到中等信任托管环境,则\xe2\ x80\x99d 明智的做法是预先将信任级别设置为“中”,以节省以后的时间和精力。

\n\n

这是一个链接

\n