创建虚拟目录并设置权限IIS7-由于权限不足而无法读取配置文件 [英] Create Virtual Directory and Set Permissions IIS7 - Cannot read configuration file due to insufficient permissions

查看:488
本文介绍了创建虚拟目录并设置权限IIS7-由于权限不足而无法读取配置文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试创建一个虚拟目录并使用IIS7和C#设置其权限.这是我的代码示例:

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.

有人可以帮忙吗?

编辑

以管理特权运行会给我一个新错误:启用读取配置文件"有人可以告诉我它应该读取哪个配置以及如何访问它吗?

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?

推荐答案

我没有正确使用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.

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

这篇关于创建虚拟目录并设置权限IIS7-由于权限不足而无法读取配置文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆