部署时抛出SecurityException异常

3
我刚写了一个MVC应用程序,并在实验室中使其运行。现在我已经将其部署到GoDaddy,但是出现了以下错误。
描述:该应用程序尝试执行安全策略不允许的操作。要授予此应用程序所需的权限,请联系系统管理员或更改配置文件中的应用程序信任级别。
异常详细信息:System.Security.SecurityException: 请求失败。
源错误:当前 Web 请求执行期间生成了未处理的异常。有关异常的起源和位置的信息可以使用下面的异常堆栈跟踪进行识别。
堆栈跟踪:
[SecurityException: 请求失败。] 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
我怀疑是我的数据库连接字符串出了问题,尽管错误似乎没有涉及到数据库。

我的真正问题是:如何解决这个问题?这些信息似乎并没有什么帮助。下一步应该怎么做?


你正在使用MVC-5吗? - user3559349
@StephenMuecke:我刚刚升级到最新版本的Visual Studio,所以我正在使用最新的版本。 - Jonathan Wood
1
我认为这将是MVC-5。我不知道GoDaddy托管和他们支持的信任级别,但这可能与MVC-5不再支持中等信任有关(参见此答案)。 - user3559349
2个回答

4

这似乎是由于我用来构建应用程序的.NET版本与主机提供的版本不匹配引起的问题。

感谢微软提供又一个错误消息,它似乎并没有告诉我关于基本问题是什么。


2
似乎问题在于 "信任级别"。您需要在 web.config 中指定站点所需的信任级别。不过问题是,GoDaddy 可能不允许您站点需要的信任级别。其中一个信任级别允许/禁止反射(例如,IoC 容器使用反射或 AutoMapper)。
信任级别是微软已经声明不再支持的东西,因此任何使其不安全的错误修复等都不再修复。因此,如果更改 web.config 无法解决您的问题,则一种解决方案可能是找到另一个 Web 主机。
示例配置:
<system.web>
  <securityPolicy>
    <trustLevel name="Full" policyFile="internal"/>
  </securityPolicy>
</system.web>

我进一步研究了一下,并在GoDaddy上找到了这篇文章:https://en.godaddy.com/help/what-trust-level-can-i-use-when-running-aspnet-2531 - Hyperdingo
当我进入设置时,它显示CAS信任级别已设置为完全。因此,就我理解的范围而言,这似乎不是问题所在。 - Jonathan Wood
对不起,我之前一直为了自己的事情一直在研究这个问题,所以非常确定它就是问题所在。但这篇文章说也有可能是由于网站不在自己的应用程序池下。你有没有权限去检查一下?https://support.microsoft.com/en-us/kb/555466 如果还是不行的话,很抱歉我无能为力。 - Hyperdingo

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接