Search code examples
asp.netvisual-studio-2010web-configashx

How to read config file values in ashx page?


I am making an application. In that application I added one ashx handler. Here I want to read some values from config file but I am not getting how to read values. I am using code as

 public class MyHandler : IHttpHandler
    { 
        public bool IsReusable 
        { 
            get { return false; } 
        } 


        public void ProcessRequest(HttpContext context) 
        { 
           //Here i want to read config values.
        } 
    } 

Solution

  • The ConfigurationManager class can be used from anywhere. You have to add reference to System.Configuration.dll, if you have not already did it.

    To read a config value

    public void ProcessRequest(HttpContext context) 
            { 
                 var cfgValue = ConfigurationManager.AppSettings["cfgKey"];
            }