我想设置IP地址和域限制在C#代码,我下面this文章,但它给了我无法识别的位置误差。IIS错误:无法识别的配置路径“MACHINE/WEBROOT/APPHOST/websiteName
Error: Unrecognized configuration path 'MACHINE/WEBROOT/APPHOST/websiteName
我的代码:
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();
}
它给了我这个错误行之后:
var ipSecuritySection = config.GetSection("system.webServer/security/ipSecurity", "websiteName");
任何一个可以告诉什么是错,什么是我错过了。
您是否在运行具有管理员权限的Visual Studio? –
@PankajKapare:我曾尝试使用管理员privilages运行visual studio,但它给出了相同的错误。 –
在第3行中,您使用的是“erverManager”而不是serverManager。我相信它的错字。 –