This is an excerp from a forum conversation I had over a ASP.Net project that could not access any Application Settings contained in the web.config file. No matter how I referenced any setting kept in my web.config file they would all come back null.
In the end the solution to the problem was that directory that served as the root directory for the IIS Website (my application was in a virtual directory in that IIS Site) had been deleted. Oddly enough it caused my application to no longer be able to access the web.config file.
I can’t access any values stored in the “AppSettings” section of my web.config file. I’m using ConfigurationSettings.AppSettings(“connectionstring”) and all I get back are nulls.
The crazy thing is that this application was working just fine a month ago. We have updated it from .net 1.0 to .net 3.5, but it was working fine. I have no idea what exactly changed. I verified that the xml markup in the web.config file is valid.
string conString = ConfigurationManager.ConnectionStrings[“DBConnectionString”].ConnectionString
Add namespace as System.Web.Configuration;
Webconfiguration is preferred one when accessing configuration file in asp.net
Darn it, I have tried both of those options with no luck.
Is there another way to set up my web.config file. I’m thinking that maybe that is the problem, although that is really just b/c I’m completely stumped here.
Anyone got any other ideas? I”m dying here.
Thanks for any help,
My mistake. What is wrong with what you is that you placed your connection string in the appsettings section. So you should use this ConfigurationManager.AppSettings[“keyName”] where keyName in your case is DBConnectionString.
Well I tried that as well. As I research this one, I’m finding out that the cause might be related to an upgrade of the framework, causing web.config to not be recognized. That is all the information I have on the problem thus far, so if anyone else might have ran into this by all means make a post.
The more I dig here the more it seems to point to a problem related to a asp.net framework upgrade on the server running it.
If the project is built using VS 2008 and it looks like it was running just fine until the box was graded to run asp.net 4.0. If that was the case that caused the project to not be able to access the web.config file how could I fix this?
This article is as close to an answer as I can find on this error. However there is no solution, it only tells how to track down where the web.config file is located.
this should work fine.
if this is not working.then paste whole coding of web.config.
so we can check it in our system
Ok So I finally figured out the problem. The home directory that I IIS Website was set up under had been deleted. The reason that the site was still returning information was that the project I was working on was actually a virtual directory located inside that same broken IIS Website.
To fix it all I did was correct the error on the main level web site and then restart the server.
This was really odd as the error that occurred due to this mistake doesn’t really make any sense to me, but hopefully this will save anyone else the trouble I went through figuring this out.