Home  »  Code Snippets  »  ASP.Net  »

How to read value from Configuration file - (app.config or web.config)

 Posted By : Manoranjan SahooPosted Date : 16/07/2011 07:12:07 AM Category : ASP.Net Points : 3

One of the best practice used in .NET application is to store the constants like Database connection in app.config in case of dll or standalone application or web.config in case of websites.

To achieve this, we have to follow below steps:

Lets consider below code in web.config

    <add key="ConnectionString" value="Data Source=DBServer;Initial Catalog=testDb; Integrated Security=True"/>

So, to read the key ConnectionString, we have to use below code in C#.

String dbConnection = System.Configuration.ConfigurationManager.

Where “ConnectionString” is the key present in web.config or app.config.

No responses found for this thread. Be the first to respond this thread.
Post Reply
Login to post Response.