【问题标题】:Security Exception ASP.NET安全异常 ASP.NET
【发布时间】:2016-07-05 12:15:55
【问题描述】:

所以我制作了这个在我的本地电脑上运行良好的应用程序,但是当我将它上传到我的网站时出现以下错误:

描述:应用程序试图执行的操作不是 安全策略允许的。授予此申请 所需权限请联系您的系统管理员或更改 应用程序在配置文件中的信任级别。例外 详细信息:System.Security.SecurityException:请求失败。

我四处搜索以解决此问题,发现将 <trust /> 元素添加到根级 web.config 可以解决此问题。我检查了我在 ASP.NET 设置中在我的网站上配置的信任级别(在本例中它设置为高),因此我在正确的 web.config 中执行了此操作:

<system.web>
    <securityPolicy>
        <trustLevel name="High" policyFile="web_hightrust.config"/>
    </securityPolicy>
    <customErrors mode="Off"/>
    <authentication mode="None"/>
    <compilation debug="true" targetFramework="4.6.1"/>
    <httpRuntime targetFramework="4.6.1"/>
    <httpModules>
        <add name="ApplicationInsightsWebTracking" type="Microsoft.ApplicationInsights.Web.ApplicationInsightsHttpModule, Microsoft.AI.Web"/>
    </httpModules>
</system.web>

这并没有解决我的问题,我没有任何途径可以探索尝试解决这个问题。下面是我收到上述错误的堆栈跟踪

[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

【问题讨论】:

  • 请将堆栈跟踪发布到代码块中以保留换行符。
  • 与您的托管服务提供商确认他们是否支持最新的 .net 版本。

标签: c# asp.net-mvc


【解决方案1】:

这听起来像是您的托管服务提供商在部分信任下运行的问题,即 Microsoft 的 no longer officially supported。你应该:

  1. 确认您的托管服务提供商确实使用了部分信任。
  2. 坚持将其删除,因为它不再受支持。
  3. 如果他们不遵守,请寻找支持完全信任的新托管服务提供商。

【讨论】:

  • 我回到 ASP.NET 设置,他们确实有 Full 选项,所以我选择了这个并将 web.config 更改为:&lt;trustLevel name="Full" policyFile="internal"/&gt; 但我仍然得到同样的错误。
猜你喜欢
  • 2010-12-02
  • 2010-09-19
  • 1970-01-01
  • 2010-11-29
  • 2010-11-26
  • 1970-01-01
  • 2010-09-21
  • 2014-06-16
相关资源
最近更新 更多