我想创建一个虚拟目录,并设置它的使用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";
}
这将引发异常和消息是:
Cannot read configuration file due to insufficient permissions.
有人能帮忙吗?
编辑
具有管理权限运行给了我一个新的错误:“启用读取配置文件”谁能告诉我这配置应该读,我怎么能访问它?
这听起来像你的应用程序没有正确的权限。 为了能够操纵IIS7的配置您的应用程序下运行的必须是管理员帐户,或由可信计算基的认可,如SYSTEM帐户的帐户的帐户。
如果你在Visual Studio调试这一点,一定要推出使用资源管理器或从快速启动工具栏上的“ 以管理员身份运行 ”功能的Visual Studio。
我用的是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;
文章来源: Create Virtual Directory and Set Permissions IIS7 - Cannot read configuration file due to insufficient permissions