Search code examples
c#.netweb-configconfigurationmanager

What is ConfigurationManager.AppSettings?


I'm using this, as a sample Authentication to try out. What I want to know is what happens in this line. i.e. ConfigurationManager.AppSettings["ActiveDirectory.ResourceId"]). Would somebody be kind enough to explain it?


Solution

  • You can set the default configurations for your application in web.config file and access them using the ConfigurationManager.AppSettings property.

    e.g.

    web.config

    <configuration>
        <appSettings>
            <add key="highestScore" value="200" />
            <add key="defaultSport" value="Cricket" />
        </appSettings>
    </configuration>
    

    Code

    int maxScore = Convert.ToInt32(ConfigurationManager.AppSettings["highestScore"]);
    string Sport = ConfigurationManager.AppSettings["defaultSport"].ToString();