创建虚拟目录并设置权限 IIS7 - 由于权限不足而无法读取配置文件

发布于 2024-08-26 13:55:40 字数 602 浏览 4 评论 0原文

我正在尝试创建一个虚拟目录并使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

蓝戈者 2024-09-02 13:55:40

这听起来像是您的应用程序没有正确的权限。为了能够操作 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.

昇り龍 2024-09-02 13:55:40

我错误地使用了 ServerManager obj。它并不期望构造函数中包含网站名称。以下是IIS7中设置匿名访问的正确方法。

using (ServerManager serverManager = new ServerManager())
                {
                    Configuration config = serverManager.GetApplicationHostConfiguration();
                    ConfigurationSection anonymouseAuthenticationSetion =                                            config.GetSection("system.webServer/security/authentication/anonymousAuthentication", webSite);
                    anonymouseAuthenticationSetion["enabled"] = true;

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.

using (ServerManager serverManager = new ServerManager())
                {
                    Configuration config = serverManager.GetApplicationHostConfiguration();
                    ConfigurationSection anonymouseAuthenticationSetion =                                            config.GetSection("system.webServer/security/authentication/anonymousAuthentication", webSite);
                    anonymouseAuthenticationSetion["enabled"] = true;
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文