[英]IIS Error: Unrecognized configuration path 'MACHINE/WEBROOT/APPHOST/websiteName
我想設置IP地址,並在C#代碼域限制 ,我下面這個文章,但它給了我無法識別的位置誤差。
錯誤:無法識別的配置路徑'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>
標記,以便其他人可以查看並建議如何修復。
老化的問題,但我想我會分享我的解決方案。
location參數必須與applicationHost.config文件中的位置路徑匹配。 這意味着如果websiteName實際上是另一個站點下的應用程序,例如默認網站,其位置部分將如下所示:
<location path="Default Web Site/websiteName">
<system.webServer>
<.../>
</system.webServer>
</location>
如果是這樣,你的第5行應如下所示:
var ipSecuritySection = config.GetSection("system.webServer/security/ipSecurity", "Default Web Site/websiteName");
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.