Система.Безопасность.SecurityException: запрос разрешения типа ' System.Безопасность.Разрешения.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, но все равно имеют ту же ошибку.

<system.web> <trust level="Full"/> ...

есть ли какие-либо настройки в IIS для настройки уровня доверия(я хотел бы преодолеть ошибку без изменения кода за файлами) ?

2 ответов


если у вас есть доступ к диспетчеру IIS (inetmgr), вы можете установить уровень доверия приложения :

  • Пуск > Выполнить > inetmgr
  • выберите веб-сайте:!--5-->
  • нажмите "уровни доверия .NET"
  • выберите "полное доверие" в раскрывающемся списке

чтобы изменить эту конфигурацию на глобальном уровне сервера iis, используйте следующую командную строку на сервере:

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

вот источник MSDN для этого info:http://technet.microsoft.com/en-us/library/cc753658 (WS.10).aspx


Если установка полного уровня доверия не работает, можно попробовать изменить пользователя пула приложений на пользователя, имеющего доступ к пути.