微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

c# – IIS错误:无法识别的配置路径’MACHINE / WEBROOT / APPHOST / websiteName

我正在尝试在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>问题中的文件标记,以便其他人可以查看并建议如何修复.

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐