5
我試圖使用C#的網站上開啓匿名身份驗證的我無法設置IIS認證編程方式使用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
有人能指導我如何解決這一問題?
看到你有C#的標籤,我猜這是ASP.NET文件 authorization> –
seekerOfKnowledge
applicationHost.config
。如果您想拒絕任何未通過身份驗證的用戶,最好在實際網站的web.config中執行此操作。這應該拒絕未經授權的用戶訪問您的網站。我實際上使用c#作爲IIS web配置器的形式。我想首先禁用匿名登錄programaticaly,然後只應用「Windows認證」 – user1593455