Config Error: This configuration section cannot be used at this path

后端 未结 30 2449
死守一世寂寞
死守一世寂寞 2020-11-22 07:01

I\'ve encountered an error deploying a site to a server. When trying to load the home page, or access authentication on the new site in IIS, I get the error:

30条回答
  •  天涯浪人
    2020-11-22 07:35

    In my case, I got this error because I was operating on the wrong configuration file.

    I was doing this:

    Configuration config = serverManager.GetWebConfiguration(websiteName);
    ConfigurationSection serverRuntimeSection = config.GetSection("system.webServer/serverRuntime");
    serverRuntimeSection["alternateHostName"] = hostname;
    

    instead of the correct code:

    Configuration config = serverManager.GetApplicationHostConfiguration();
    ConfigurationSection serverRuntimeSection = configApp.GetSection("system.webServer/serverRuntime", websiteName);
    serverRuntimeSection["alternateHostName"] = hostname;
    

    in other words, I was trying to operate on the website's web.config instead of the global file C:\Windows\System32\inetsrv\config\applicationHost.config, which has a section (or can have a section) for the website. The setting I was trying to change exists only in the applicationHost.config file.

提交回复
热议问题