System.Security.SecurityException:请求类型为’System.Security.Permissions.EnvironmentPermission,mscorlib’的权限失败

当我尝试运行“已发布”的本地网站时,我收到以下错误。

Server Error in '/' Application. -------------------------------------------------------------------------------- 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 for the permission of type 'System.Security.Permissions.EnvironmentPermission, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' 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 for the permission of type 'System.Security.Permissions.EnvironmentPermission, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed.] System.Security.CodeAccessSecurityEngine.Check(Object demand, StackCrawlMark& stackMark, Boolean isPermSet) +0 System.Security.CodeAccessPermission.Demand() +54 System.Environment.ExpandEnvironmentVariables(String name) +650 cc..cctor() +88 -------------------------------------------------------------------------------- Version Information: Microsoft .NET Framework Version:2.0.50727.4927; ASP.NET Version:2.0.50727.4927 

阅读一些博客后,我在Web.config添加了以下内容,但仍然有相同的错误。

...

IIS中是否有任何设置来配置信任级别(我想在不更改文件后面的代码的情况下克服错误)?

如果您可以访问IIS管理器(inetmgr),则可以设置应用程序的信任级别:

  • 开始>运行> inetmgr
  • 选择您的网站
  • 点击“.NET Trust Levels”
  • 在下拉列表中选择“完全信任”

要在iis服务器的全局级别更改此配置,请在服务器上使用以下命令行:

 appcmd set config /commit:WEBROOT /section:trust /level:Full 

以下是该信息的MSDN源: http : //technet.microsoft.com/en-us/library/cc753658(WS.10).aspx

如果将信任级别设置为“完全”不起作用,则可以尝试将应用程序池用户更改为有权访问该路径的用户。