Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Improve flexibility of ASP.Net application with the help of AppSettings in Web.config file

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 363
    Comment on it

    In asp.net application, we Web.config file by default when we create an application. This file is used for keeping various configuration setting related to application i.e. Framework Version, Entity framework settings etc. Other than these configurations, we can also add our custom keys and their values in this file.

    These Keys and their values can be changed at any time without even rebuilding the application and they will have immediate effect wherever the are being used in the application

     

    The <appSettings> element of a web.config file is a place to store configurable values and these values can be read in the application with their key name.  Here is the example of this section

    <appSettings>
        <add key="YourKeyName" value="ValueOfYourKey" />
     </appSettings>

    We can define any key in this section and we can read the same in our application.

    Here is the sample code for reading this value

    string myKeyValue= ConfigurationSettings.AppSettings["YourKeyName"];

    As shown above, To read the key we use the ConfigurationSettings class from the System.Configuration namespace.

    If you want to change the value of this field then you can open the Web.config file,change the value and then save the file. As soon as you save the file, the new value of the key will come into effect wherever it is being read in entire application.

     

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: