Reputation:
In my Visual Studio Web project is a Web.config
at the root.
That Web.config
file defines a network User and Password that is used for basic network authentication.
<configuration>
<appSettings>
<add key="User" value="victoria"/>
<add key="Pwd" value="i12kissU"/>
</appSettings>
</configuration>
My Project uses a Master Page that houses several common methods. Here is where I use the App Settings above:
Master Page:
using System.Net;
using System.Web.Configuration;
//
public CredentialCache GetNetworkCredentials(string url) {
var item = new CredentialCache();
var username = WebConfigurationManager.AppSettings["User"];
var password = WebConfigurationManager.AppSettings["Pwd"];
item.Add(new Uri(url), "Basic", new NetworkCredential(username, password));
return item;
}
In each SubFolder, the Project has routines that access different databases on the SQL Server. Therefore, each SubFolder has its own Web.config
file with a unique database connection string for those tables.
<configuration>
<connectionStrings>
<add name="SubFolderN" connectionString="Data Source=.\SQLEXPRESS;Initial Catalog=SubFolderN;User Id=UserN;Password=PwdN" providerName="System.Data.SqlClient" />
</connectionStrings>
</configuration>
That lets me pull the Connection String for each SubFolder.
SubFolderN:
ConnectionString =
WebConfigurationManager.ConnectionStrings["SubFolderN"].ConnectionString;
So far, each SubFolder successfully pulls the User
and Pwd
values from Master Page.
So far the results seem promising.
However, I'd like to confirm with someone that knows in the community that what I am seeing not a result of browser caching. I need this to occur consistently.
A link with an authoritative reference would be great.
Upvotes: 1
Views: 10054
Reputation:
I think I found the answer here:
10 Things ASP.NET Developers Should Know About Web.config Inheritance and Overrides
Specifically, it says of the ASP.NET Web.config:
The Web.config file for a specific ASP.NET application is located in the root directory of the application and contains settings that apply to the Web application and inherit downward through all of the subdirectories in its branch.
Upvotes: 5