创建虚拟目录并设置权限 IIS7 - 由于权限不足而无法读取配置文件
我正在尝试创建一个虚拟目录并使用 IIS7 和 C# 设置它的权限。这是我的代码示例:
using (ServerManager serverManager = new ServerManager(webSite))
{
ConfigurationSection anonymousAuthenticationSection =
config.GetSection(
@"system.webServer/security/authentication/anonymousAuthentication",
webSite);
anonymousAuthenticationSection["enabled"] = true;
serverManager.CommitChanges();
return "true";
}
这会引发异常,消息为:
由于权限不足,无法读取配置文件。
有人可以帮忙吗?
编辑
使用管理权限运行会出现一个新错误:“启用读取配置文件”有人可以告诉我它应该读取哪个配置以及如何访问它吗?
I am trying to create a virtual directory and set it's permissions using IIS7 and C#. Here is a sample of my code:
using (ServerManager serverManager = new ServerManager(webSite))
{
ConfigurationSection anonymousAuthenticationSection =
config.GetSection(
@"system.webServer/security/authentication/anonymousAuthentication",
webSite);
anonymousAuthenticationSection["enabled"] = true;
serverManager.CommitChanges();
return "true";
}
This throws an exception and the message is:
Cannot read configuration file due to insufficient permissions.
Can someone help?
EDIT
Running with administration privileges gives me a new error: "Enable to read configuration file" Can someone tell me which config it should be reading and how I can access it?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这听起来像是您的应用程序没有正确的权限。为了能够操作 IIS7 的配置,您的应用程序运行所使用的帐户必须是管理员帐户,或者是受信任的计算库识别的帐户,例如 SYSTEM 帐户。
如果您在 Visual Studio 中对此进行调试,请务必使用资源管理器中的“以管理员身份运行”功能或从快速启动工具栏启动 Visual Studio。
This sounds like your application doesn't have the correct permissions. To be able to manipulate IIS7's configuration the account your application runs under must be an Administrator account, or an account that is recognised by the trusted computing base such as the SYSTEM account.
If you're debugging this in Visual Studio, be sure to launch Visual Studio using the "Run as Administrator" feature in explorer or from the quicklaunch toolbar.
我错误地使用了 ServerManager obj。它并不期望构造函数中包含网站名称。以下是IIS7中设置匿名访问的正确方法。
I was using the ServerManager obj incorrectly. It was not expecting the website name in the constructor. The following is the correct way to set anonymous access in IIS7.