c# - IIS 错误 : Unrecognized configuration path 'MACHINE/WEBROOT/APPHOST/websiteName

标签 c# asp.net iis

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

关于c# - IIS 错误 : Unrecognized configuration path 'MACHINE/WEBROOT/APPHOST/websiteName,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44133547/

相关文章:

javascript - 如何从代码隐藏中读取JavaScript设置的文本框文本?

c# - Windows Azure - 在 Windows Azure IIS 存储中提供未知 (mp4) MIME 类型

asp.net - ASP.Net 使用什么 URL 重写器?

c# - 查找系统和程序内存使用情况的替代方法

c# - 在 Xamarin 表单中实现分层 StackLayout 的延迟加载

c# - 与localhost C#的双向通信

c# - 使用 Windows 进程备份 IIS 设置

c# - Json.NET StringEnumConverter 并不总是有效

ASP.NET 文件上传进度条

asp.net - 为什么 SignalR 在我的 Angular Web 应用程序中的协商调用中收到 404?