我正在尝试使用c#
在网站上启用匿名身份验证此代码抛出在底部写的异常我搜索到的地方我无法找到答案如何解决它:
using (ServerManager serverManager = new ServerManager())
{
Configuration configapp = serverManager.GetApplicationHostConfiguration();
ConfigurationSection anonymousAuthenticationSection = configapp.GetSection("system.webServer/security/authentication/anonymousAuthentication", Site1);
anonymousAuthenticationSection["enabled"] = false;
serverManager.CommitChanges();
}
例外:
System.IO.FileNotFoundException: Filename: \\?\C:\Windows\system32\inetsrv\config\applicationHost.config
Error: Unrecognized configuration path 'MACHINE/WEBROOT/APPHOST/Site1'
at Microsoft.Web.Administration.Interop.AppHostWritableAdminManager.GetAdminSection(String bstrSectionName, String bstrSectionPath)
at Microsoft.Web.Administration.Configuration.GetSectionInternal(ConfigurationSection section, String sectionPath, String locationPath)
at Microsoft.Web.Administration.Configuration.GetSection(String sectionPath, String locationPath)
at FlowSuiteWebConfigurator.label.button1_Click(Object sender, EventArgs e) in C:\Users\Administrator\documents\visual studio 2010\Projects\Projectname\Projectname\Form1.cs:line 264
有人可以指导我如何解决这个问题吗?
答案 0 :(得分:2)
可能有点晚了(1年半之后......),但问题似乎在你的位置定义(configapp.GetSection的第二个参数):异常说Error: Unrecognized configuration path 'MACHINE/WEBROOT/APPHOST/Site1'
在我的计算机上进行本地测试,我对例如Default Web Site/MyCustomPortal
的有效位置名称没有例外。
注意:在Microsoft.Web.Administration.dll
下添加的引用为C:\Windows\System32\inetsrv\
,这些代码行会查看applicationHost.config
C:\Windows\System32\inetsrv\config