Вы можете использовать Microsoft.Web.Administration, или AppCmd, или Javascript (COM - AHADMIN), чтобы сделать это, вот несколько примеров того, как удалить:
private static void Main() {
using(ServerManager serverManager = new ServerManager()) {
Configuration config = serverManager.GetApplicationHostConfiguration();
ConfigurationSection ipSecuritySection = config.GetSection("system.webServer/security/ipSecurity");
ConfigurationElementCollection ipSecurityCollection = ipSecuritySection.GetCollection();
ConfigurationElement addElement = FindElement(ipSecurityCollection, "add", "ipAddress", @"169.132.124.234", "subnetMask", @"255.255.255.255", "domainName", @"");
if (addElement == null) throw new InvalidOperationException("Element not found!");
ipSecurityCollection.Remove(addElement);
serverManager.CommitChanges();
}
}
private static ConfigurationElement FindElement(ConfigurationElementCollection collection, string elementTagName, params string[] keyValues) {
foreach (ConfigurationElement element in collection) {
if (String.Equals(element.ElementTagName, elementTagName, StringComparison.OrdinalIgnoreCase)) {
bool matches = true;
for (int i = 0; i < keyValues.Length; i += 2) {
object o = element.GetAttributeValue(keyValues[i]);
string value = null;
if (o != null) {
value = o.ToString();
}
if (!String.Equals(value, keyValues[i + 1], StringComparison.OrdinalIgnoreCase)) {
matches = false;
break;
}
}
if (matches) {
return element;
}
}
}
return null;
}
Использование Javascript:
var adminManager = new ActiveXObject ('Microsoft.ApplicationHost.WritableAdminManager');adminManager.CommitPath = "MACHINE / WEBROOT / APPHOST";
var ipSecuritySection = adminManager.GetAdminSection ("system.webServer / security / ipSecurity", "MACHINE / WEBROOT / APPHOST" 100 * 100 * 9 *) *;var ipSecurityCollection = ipSecuritySection.Collection;
var addElementPos = FindElement (ipSecurityCollection, «add», [«ipAddress», «169.132.124.234», «subnetMask», «255.255.255.255», domain, 255.255.255.255 », domain,«]);if (addElementPos == -1) throw «Элемент не найден!»;
ipSecurityCollection.DeleteElement (addElementPos);
adminManager.CommitChanges ();
function FindElement (collection, elementTagName, valuesToMatch) {для (var i = 0; i
if (element.Name == elementTagName) {
var matches = true;
for (var iVal = 0; iVal < valuesToMatch.length; iVal += 2) {
var property = element.GetPropertyByName(valuesToMatch[iVal]);
var value = property.Value;
if (value != null) {
value = value.toString();
}
if (value != valuesToMatch[iVal + 1]) {
matches = false;
break;
}
}
if (matches) {
return i;
}
}
}
return -1;
}
АНаконец, AppCmd.exe:
appcmd.exe set config -section: system.webServer / security / ipSecurity /-"[ipAddress='169.132.124.234',subnetMask='255.255.255.255',domainName= ''] "/совершить: apphost