部署时抛出 SecurityException
SecurityException thrown on deployment
我刚刚编写了一个 MVC 应用程序并让它在我的实验室中运行。现在我已经将它部署到 GoDaddy,但出现以下错误。
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.
堆栈跟踪:
[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
我想知道我的数据库连接字符串,虽然这个错误似乎并不表明数据库有任何问题。
所以我真正的问题是:如何解决这个问题。这些消息似乎根本没有帮助。下一步可能是什么?
看来问题出在 "Trust level"。您需要在 web.config 中为您的站点指定所需的信任级别。但问题是 GoDaddy 可能不允许您的站点所需的信任级别。信任级别之一 allows/disallows 例如反射(例如 IoC 容器使用反射或 AutoMapper)。
Microsoft 已声明不再支持信任级别,因此不再修复任何使其不安全的错误修复等。因此,一个解决方案可能是寻找另一个虚拟主机,因为对 web.config 的更改无法解决您的问题。
示例配置:
<system.web>
<securityPolicy>
<trustLevel name="Full" policyFile="internal"/>
</securityPolicy>
</system.web>
这似乎是我用来构建我的应用程序的 .NET 版本与主机上提供的版本不匹配的问题。
感谢 Microsoft 的另一条错误消息,它似乎没有告诉我根本问题是什么。
我刚刚编写了一个 MVC 应用程序并让它在我的实验室中运行。现在我已经将它部署到 GoDaddy,但出现以下错误。
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.
堆栈跟踪:
[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
我想知道我的数据库连接字符串,虽然这个错误似乎并不表明数据库有任何问题。
所以我真正的问题是:如何解决这个问题。这些消息似乎根本没有帮助。下一步可能是什么?
看来问题出在 "Trust level"。您需要在 web.config 中为您的站点指定所需的信任级别。但问题是 GoDaddy 可能不允许您的站点所需的信任级别。信任级别之一 allows/disallows 例如反射(例如 IoC 容器使用反射或 AutoMapper)。
Microsoft 已声明不再支持信任级别,因此不再修复任何使其不安全的错误修复等。因此,一个解决方案可能是寻找另一个虚拟主机,因为对 web.config 的更改无法解决您的问题。
示例配置:
<system.web>
<securityPolicy>
<trustLevel name="Full" policyFile="internal"/>
</securityPolicy>
</system.web>
这似乎是我用来构建我的应用程序的 .NET 版本与主机上提供的版本不匹配的问题。
感谢 Microsoft 的另一条错误消息,它似乎没有告诉我根本问题是什么。