IIS Error: Unrecognized configuration path "MACHINE / WEBROOT / APPHOST / websiteName

I am trying to set the IP address and domain restrictions in C # code, I am following this article, but this gives me an unrecognized location error.

Error: unrecognized configuration path "MACHINE / WEBROOT / APPHOST / websiteName

My code is:

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

            }

It gives me an error after this line:

var ipSecuritySection = config.GetSection ("system.webServer / security / ipSecurity", "websiteName");

Can anyone say what is wrong or something that I missed.

+4
source share
2 answers

applicationHost.config IIS/IIS Express, - . , , <sites> , , .

0

, .

applicationHost.config. , _ , . - , :

<location path="Default Web Site/websiteName">
    <system.webServer>
      <.../> 
    </system.webServer>
</location>

, 5 :

var ipSecuritySection = config.GetSection("system.webServer/security/ipSecurity", "Default Web Site/websiteName");
0

Source: https://habr.com/ru/post/1677757/


All Articles