加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

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文章,但它给了我无法识别的位置错误.

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”);

任何人都可以说出错误,或者我错过了什么.

解决方法

您可能会在IIS / IIS Express中获得一个损坏的applicationHost.config,其中该网站无法拥有根应用程序.如果您不知道如何编辑,请发布< sites>问题中的文件标记,以便其他人可以查看并建议如何修复.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读