Click here to Skip to main content
15,911,142 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have an asp site. I have some aspx also and put those pages into the asp site. Now I am able to access those pages through the asp site. However, there are some pages those are fetching the connection string or some AppSetting key-values from the web.config value.

C#
connectionString = 
  Convert.ToString(System.Configuration.ConfigurationManager.AppSettings["ConnString"]);



But as soon as I access those pages it shows the error

C#
The ConnectionString property has not been initialized.


I have put the following code in the home.aspx page and called the page in the browser. But it does not show any value.

C#
<% Response.Write(Convert.ToString(System.Configuration.ConfigurationManager.AppSettings["ConnString"]);) %>


Please let me know how to access the web.config file values through the aspx page those are inside of the asp site. The web.config file and those pages are on the same root folder. Is there any setting in the IIS?
Posted
Comments
Anisuzzaman Sumon 12-Feb-15 0:56am    
We cannot see your PC nor we read your mind .please show contents of Web.config and .Show more code.

1 solution

Hello,

First define your value in web.config as per below code,
<configuration>
<appsettings>
<add key="Connstring" value="your value" />
</appsettings>
</configuration>


Then write below code in your aspx.cs page,
string Connstring = System.Configuration.ConfigurationManager.AppSettings["Connstring"];
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900