【发布时间】:2017-05-23 11:28:49
【问题描述】:
我正在尝试在 c# 代码中设置 IP 地址和域限制,我正在关注 this 文章,但它给了我无法识别的位置错误。
错误:无法识别的配置路径“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:我尝试使用管理员权限运行 Visual Studio,但它给出了同样的错误。
-
在第 3 行中,您使用的是“erverManager”而不是 serverManager。我相信它的错字。
-
@PankajKapare:是的,它的错字,我要编辑它。谢谢。