locked
ServerManager gives error: Cannot Read Configuration File RRS feed

  • Question

  • User-1429344198 posted
    Hello, I need to set permissions on a virtual directory from within my C# application. I am hosting the website with iis7. I am attempting to get the particular site and then set it's Configuration Section (ystem.webServer/security/authentication/anonymousAuthentication) to enabled. This is a snippit of the code that I am attempting: using (ServerManager serverManager = new ServerManager(webSite)) { Configuration config = serverManager.GetApplicationHostConfiguration() ConfigurationSection anonymouseAuthenticationSetion = config.GetSection("system.webServer/security/authentication/anonymousAuthentication"); anonymouseAuthenticationSetion["enabled"] = true This results in an exception message "Error: Cannot Read Configuration File". Can anyone tell me what I am doing wrong here?
    Tuesday, March 23, 2010 9:40 AM

Answers

  • User-47214744 posted

    The reason is because you are passing the website to the ServerManager ctor that does not expect that, you should pass it to the GetSection overload. Here is how it should look like:


    using (ServerManager serverManager = new ServerManager()) {
        Configuration config = serverManager.GetApplicationHostConfiguration();
        ConfigurationSection anonymouseAuthenticationSetion = config.GetSection("system.webServer/security/authentication/anonymousAuthentication", webSite);
        anonymouseAuthenticationSetion["enabled"] = true;
        serverManager.CommitChanges();
    }

    • Marked as answer by Anonymous Tuesday, September 28, 2021 12:00 AM
    Tuesday, March 23, 2010 11:01 AM

All replies

  • User-47214744 posted

    The reason is because you are passing the website to the ServerManager ctor that does not expect that, you should pass it to the GetSection overload. Here is how it should look like:


    using (ServerManager serverManager = new ServerManager()) {
        Configuration config = serverManager.GetApplicationHostConfiguration();
        ConfigurationSection anonymouseAuthenticationSetion = config.GetSection("system.webServer/security/authentication/anonymousAuthentication", webSite);
        anonymouseAuthenticationSetion["enabled"] = true;
        serverManager.CommitChanges();
    }

    • Marked as answer by Anonymous Tuesday, September 28, 2021 12:00 AM
    Tuesday, March 23, 2010 11:01 AM
  • User-1480425032 posted

    Please, try out this.

    1. Create ServerManager with default constructor.

    ie) ServerManager serverManager = new ServerManager();

    2. Call CommitChanges() once you have done change configuration.

    ie) serverManager.CommitChanges();

    Tuesday, March 23, 2010 11:25 AM
  • User-1429344198 posted
    Awesome. You are the man. Worked like a charm. Thanks!
    Tuesday, March 23, 2010 11:55 AM