I am trying to set IP Address and Domain Restrictions in the c# code, i am following this article, but it gives me unrecognized location error.
Error: Unrecognized configuration path 'MACHINE/WEBROOT/APPHOST/websiteName
My Code:
using (var serverManager = new ServerManager())
{
var config = serverManager.GetApplicationHostConfiguration();
var ipSecuritySection = config.GetSection("system.webServer/security/ipSecurity", "websiteName");
var ipSecurityCollection = ipSecuritySection.GetCollection();
var addElement = ipSecurityCollection.CreateElement("add");
addElement["ipAddress"] = @"SomeIP";
addElement["allowed"] = false;
ipSecurityCollection.Add(addElement);
var addElement1 = ipSecurityCollection.CreateElement("add");
addElement1["ipAddress"] = @"SomeIP";
addElement1["subnetMask"] = @"255.255.0.0";
addElement1["allowed"] = false;
ipSecurityCollection.Add(addElement1);
serverManager.CommitChanges();
}
It gives me error after this line:
var ipSecuritySection = config.GetSection("system.webServer/security/ipSecurity", "websiteName");
Can any one tell what is wrong, or something that i have missed.