【发布时间】: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