c# – IIS错误:无法识别的配置路径’MACHINE / WEBROOT / APPHO
发布时间:2020-12-15 21:06:44 所属栏目:百科 来源:网络整理
导读:我正在尝试在c#代码中设置IP地址和域限制,我正在关注 this文章,但它给了我无法识别的位置错误. Error: Unrecognized configuration path ‘MACHINE/WEBROOT/APPHOST/websiteName 我的代码: using (var serverManager = new ServerManager()) { var config =
我正在尝试在c#代码中设置IP地址和域限制,我正在关注
this文章,但它给了我无法识别的位置错误.
我的代码: 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(); } 在这一行之后它给了我错误:
任何人都可以说出错误,或者我错过了什么. 解决方法
您可能会在IIS / IIS Express中获得一个损坏的applicationHost.config,其中该网站无法拥有根应用程序.如果您不知道如何编辑,请发布< sites>问题中的文件标记,以便其他人可以查看并建议如何修复.
(编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |