I am using iis 8.0 and trying to remove any allowed/restricted ip address from the list, screen shot is attached. i have used the remove variable by following this link .
var websiteName = "abc.com";
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("remove");
addElement["ipAddress"] = ipAddress;
ipSecurityCollection.Remove(addElement);
serverManager.CommitChanges();
}
Guide me am i doing wrong, if yes? then what is it.
I have found the way to remove entry from the collection.
var websiteName = "abc.com";
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("remove");
addElement["ipAddress"] = ipAddress;
ipSecurityCollection.add(addElement);
serverManager.CommitChanges();
}
Every thing was alright only one thing was wrong in the 2nd last line.
ipSecurityCollection.remove(addElement);
Change it to
ipSecurityCollection.add(addElement);
After that it will work perfectly.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.