Wednesday 15 April 2015

c# 4.0 - accessing values of web.config file in newly created project under existing .net application hosted on IIS -


I have a classic asp project, hosted with the Net 4.0 framework on IIS. The project uses some .NET DLL so that a bin folder in the root and the web Config file

I have created a new clean project and the app settings link string key file from the root settings, since I want to place the connection string in one place.
But I'm getting the following address: System.NullReferenceException: Object reference is not set to an instance of an object

I have my project dll in my main root bin folder from my project The config file has also been deleted so we have only one configuration file in the root so the entire site is working with a single app pool.

Please tell me how I can use values ​​of the root config file in my newly created project.

Add references:

  using System.Web.Configuration ;   

In the config file:

  & lt; Configuration & gt; & Lt; App settings & gt; & Lt; Key = "KeyName" value = "KeyValue" /> Add & lt; / App settings & gt; & Lt; / Configuration & gt;   

In your code:

  string value = web configuration manager. AppSettings ["KeyName"];             P>          div> 

No comments:

Post a Comment