了解子文件夹中的Web.config层次结构 [英] Understanding Web.config Hierarchy in SubFolders

查看:75
本文介绍了了解子文件夹中的Web.config层次结构的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的Visual Studio Web项目中,根目录是 Web.config .

In my Visual Studio Web project is a Web.config at the root.

Web.config 文件定义了用于基本网络身份验证的网络 User Password .

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:

母版页:

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;
}

在每个 SubFolder 中,项目都有访问SQL Server上不同数据库的例程.因此,每个 SubFolder 都有其自己的 Web.config 文件,这些文件具有这些表的唯一数据库连接字符串.

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>

这使我可以为每个 SubFolder 拉动连接字符串.

That lets me pull the Connection String for each SubFolder.

SubFolderN:

ConnectionString =
  WebConfigurationManager.ConnectionStrings["SubFolderN"].ConnectionString;

到目前为止,每个 SubFolder 都已成功从母版页中提取 User Pwd 值.

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.

推荐答案

我想我在这里找到了答案:

I think I found the answer here:

具体地说,它说的是ASP.NET Web.config:

Specifically, it says of the ASP.NET Web.config:

特定ASP.NET应用程序的Web.config文件位于该应用程序的根目录中,并且包含适用于该Web应用程序的设置,并通过其分支中的所有子目录向下继承.

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.

这篇关于了解子文件夹中的Web.config层次结构的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆