visual-studio 在网络共享或 Intranet 项目上编译网站时,请求类型“System.Web.AspNetHostingPermission”的权限失败
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2769040/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Request for the permission of type 'System.Web.AspNetHostingPermission' failed when compiling web site on a Network Share or Intranet Project
提问by ahsteele
I have been using Windows 7 for a while but have not had to work with a particular legacy intranet application since my upgrade. Unfortunately, this application is setup as an ASP.NET Website project hosted on an intranet server. When I have the website open in Visual Studio 2008 and try to debug it, I receive the following compiler error:
我已经使用 Windows 7 一段时间了,但自从我升级以来,我不必使用特定的旧版 Intranet 应用程序。不幸的是,此应用程序被设置为托管在 Intranet 服务器上的 ASP.NET 网站项目。当我在 Visual Studio 2008 中打开网站并尝试调试它时,我收到以下编译器错误:
Request for the permission of type 'System.Web.AspNetHostingPermission' failed
请求“System.Web.AspNetHostingPermission”类型的权限失败
To resolve this issue on Windows Vista machines, I would change the machine's .NET Security Configuration trust level to full for the local intranet (fix outlined here). I believe this configuration utility relied upon the mscorcfg.msc which from some cursory research appears to be apart of the .NET 2.0 SDK. I have tried to follow the instructions from this Microsoft Support articlerunning the command below to no avail.
要在 Windows Vista 机器上解决此问题,我会将机器的 .NET 安全配置信任级别更改为本地 Intranet 的完全信任级别(此处概述了修复程序)。我相信这个配置实用程序依赖于 mscorcfg.msc,从一些粗略的研究来看,它似乎是 .NET 2.0 SDK 的一部分。我已尝试按照此Microsoft 支持文章中的说明运行以下命令,但无济于事。
Drive:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\caspol.exe -m -ag 1 -url "file:////\computername\sharename\*" FullTrust -exclusive on
Presently, I have the following .NET, ASP.NET, and .NET SDK components installed on my machine
目前,我的机器上安装了以下 .NET、ASP.NET 和 .NET SDK 组件
- Microsoft .NET Compact Framework 2.0 SP2
- Microsoft .NET Compact Framework 3.5
- Microsoft .NET Framework 4 Client Profile
- Microsoft .NET Framework 4 Extended
- Microsoft .NET Framework 4 Multi-Targeting Pack
- Microsoft ASP.NET MVC 1.0
- Microsoft ASP.NET MVC 2
- Microsoft ASP.NET MVC 2 - Visual Studio 2008 Tools
- Microsoft ASP.NET MVC 2 - Visual Studio 2010 Tools
- Microsoft Windows SDK for Visual Studio 2008 .NET Framework Tools - enu
- Microsoft Windows SDK for Visual Studio 2008 Headers and Libraries
- Microsoft Windows SDK for Visual Studio 2008 SDK Reference Assemblies and IntelliSense
- Microsoft Windows SDK for Visual Studio 2008 SP1 Tools
- Microsoft Windows SDK for Visual Studio 2008 SP1 Win32 Tools
- Microsoft Windows SDK for Windows Server 2008 (6001.18000.367)
- Microsoft .NET 精简框架 2.0 SP2
- Microsoft .NET 精简框架 3.5
- Microsoft .NET Framework 4 客户端配置文件
- Microsoft .NET Framework 4 扩展
- Microsoft .NET Framework 4 多目标包
- 微软 ASP.NET MVC 1.0
- 微软 ASP.NET MVC 2
- Microsoft ASP.NET MVC 2 - Visual Studio 2008 工具
- Microsoft ASP.NET MVC 2 - Visual Studio 2010 工具
- 适用于 Visual Studio 2008 .NET Framework 工具的 Microsoft Windows SDK - zh
- 用于 Visual Studio 2008 标头和库的 Microsoft Windows SDK
- 适用于 Visual Studio 2008 SDK 参考程序集和 IntelliSense 的 Microsoft Windows SDK
- 适用于 Visual Studio 2008 SP1 工具的 Microsoft Windows SDK
- 适用于 Visual Studio 2008 SP1 Win32 工具的 Microsoft Windows SDK
- 适用于 Windows Server 2008 的 Microsoft Windows SDK (6001.18000.367)
Do I need to install the .NET 2.0 SDK? Am I issuing the caspolcommand incorrectly? Is there something else that I am missing?
我是否需要安装 .NET 2.0 SDK?我是否caspol错误地发出命令?还有什么我想念的吗?
回答by ahsteele
After some additional digging I came across a blog post by Aaron Stebner covering Details about setup for the .NET Framework 2.0 configuration tool. Stebner details how the Configuration Utility was removed from the .NET redistributable and placed only in the SDK. Not a big deal a few years ago but now that the community relies upon newer SDKs and only installs the redistributable / compact versions of the framework we have lost access to the .NET Framework 2.0 Configuration Tool.
经过一些额外的挖掘,我发现了 Aaron Stebner 的一篇博客文章,其中介绍了有关 .NET Framework 2.0 配置工具设置的详细信息。Stebner 详细说明了如何从 .NET 可再发行组件中删除配置实用程序并仅将其放置在 SDK 中。几年前没什么大不了的,但现在社区依赖较新的 SDK 并且只安装框架的可再发行/压缩版本,我们无法访问 .NET Framework 2.0 配置工具。
The official answer from Microsoft is to Configure Security Policy Using the Code Access Security Policy Tool (Caspol.exe). Unfortunately, this command line utility did not work for me. I however, do not rule out user error as to why it failed.
Microsoft 的官方答案是使用代码访问安全策略工具 (Caspol.exe) 配置安全策略。不幸的是,这个命令行实用程序对我不起作用。但是,我不排除用户错误导致失败的原因。
Ultimately, Stebner solved my issue because he provides an installer for the configuration tool. Which once I had the configuration utility installed allowed me follow the steps outlined in th DotNetSlackers article System.Web.AspNetHostingPermission when Accessing Network or Intranet Projects using Visual Studio 2005which I have paraphrased into steps below.
最终,Stebner 解决了我的问题,因为他为配置工具提供了安装程序。一旦我安装了配置实用程序,我就可以按照DotNetSlackers 文章 System.Web.AspNetHostingPermission 中概述的步骤使用 Visual Studio 2005 访问网络或 Intranet 项目,我已将其转述为以下步骤。
To change the local machine's .NET Security Settings goto
要更改本地计算机的 .NET 安全设置,请转到
Start > Control Panel > Administrative Tools > Microsoft .NET Framework 2.0 Configuration
开始 > 控制面板 > 管理工具 > Microsoft .NET Framework 2.0 配置
Fully expand My Computerand select Runtime Security Policy. On the right, choose Adjust Zone Security. Leave the default option (Make changes to this computer) and hit next. Choose Local Intranetand change the trust level to Full Trust. Then choose Next and then Finish. Restart Visual Studio and you should be all set.
完全展开My Computer并选择Runtime Security Policy。在右侧,选择Adjust Zone Security。保留默认选项(更改此计算机)并点击下一步。选择Local Intranet并将信任级别更改为Full Trust。然后选择下一步,然后选择完成。重新启动 Visual Studio,你应该一切都准备好了。
回答by splattne
Try to change the application pool setting Load User Profileto True.
尝试将应用程序池设置更改Load User Profile为True.
In Windows 7 it is set to Falseby default. It seems that in Windows Vista IIS 7 sets this automatically for you.
在 Windows 7 中,它False默认设置为。似乎在 Windows Vista IIS 7 中会自动为您设置。
回答by Tarek El-Mallah
this problem happens to me and the solution was easy, I just add permission fro the application pool user on the physical files, then make IISReset, and it's working now.
这个问题发生在我身上,解决方案很简单,我只需在物理文件上添加应用程序池用户的权限,然后进行 IISReset,现在它正在工作。

