I am trying to set the IP address and domain restrictions in C # code, I am following this article, but this gives me an unrecognized location error.
Error: unrecognized configuration path "MACHINE / WEBROOT / APPHOST / websiteName
My code is:
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 an error after this line:
var ipSecuritySection = config.GetSection ("system.webServer / security / ipSecurity", "websiteName");
Can anyone say what is wrong or something that I missed.
source
share