I'm trying to turn of Anonymous authentication on a site using c#
This code throws exception written at bottom i searched everywhere i cant find answer how to solve it:
using (ServerManager serverManager = new ServerManager())
{
Configuration configapp = serverManager.GetApplicationHostConfiguration();
ConfigurationSection anonymousAuthenticationSection = configapp.GetSection("system.webServer/security/authentication/anonymousAuthentication", Site1);
anonymousAuthenticationSection["enabled"] = false;
serverManager.CommitChanges();
}
The exception:
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
Can someone guide me how to fix this?
A bit late maybe (1 year and a half after...), but the problem seems to be in your location definition (2nd parameter of configapp.GetSection): the exception said Error: Unrecognized configuration path 'MACHINE/WEBROOT/APPHOST/Site1'
Tested locally on my machine, I have no exception with a valid location name like Default Web Site/MyCustomPortal
.
Note: the reference added is Microsoft.Web.Administration.dll
under C:\Windows\System32\inetsrv\
, and those lines of code look into the file applicationHost.config
located in C:\Windows\System32\inetsrv\config
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With