Web.Config 回退到 Web Farm 中的全局配置

发布于 2024-07-07 15:24:01 字数 689 浏览 8 评论 0原文

这个问题让办公室里的我们几个人难住了。 我们对于将 ASP.NET 应用程序部署到网络场都是新手,而且我也没有什么想法。

我们有一个网络场,并且应用程序被复制到所有网络场上。 但是,我们遇到了问题。

尝试从 appSettings 获取设置时抛出异常。 经过进一步调查,发现该节点实际上没有使用本地 Web.Config ,而是回退到 .NET Framework 文件夹中的 Web.Config (我们有通过在那里添加键来证明这一点,这些键出现在测试页上)。

我一定错过了一些东西,因为我的理解是,只要该文件在那里,IIS 就应该使用它! 其中一台服务器似乎工作正常!

以下是我们已确认的内容的列表:

  • 配置文件位于应用程序目录中。
  • 该文件的内容是正确的。
  • 从 IIS 查看文件时> 网站> 属性> ASP.NET > 编辑配置显示正确的内容。

但是,在运行时使用的文件是全局文件 (windows\ms .net\framework\v2\config\web.config)。

有人对可能出现的问题有什么建议吗? 感谢我能得到的所有帮助!

谢谢。

This problem has several of us stumped in the office. We are all new to deploying ASP.NET apps to a web farm, and I am fresh out of ideas.

We have a web farm, and the application is copied on to all of them.
However, we are having a problem..

An exception is being thrown when trying to get settings from appSettings. Upon further investigation, it turns out the node is actually not using the local Web.Config but it falling back to the Web.Config in the .NET framework folder (we have proved this by adding keys there, which appear on a test page).

I must be missing something, because my understanding is that so long as the file is there, IIS should use that! One of the servers seems to work fine!

Here's a list of what we have confirmed:

  • The config file is in the app directory.
  • Said file's content is correct.
  • When viewing the file from IIS > Site > Properties > ASP.NET > Edit Config the correct content is shown.

However, at run-time the file that is used is the global one (windows\ms .net\framework\v2\config\web.config).

Anyone have any suggestions as to what may be going wrong? Appreciate all the help I can get!

Thanks.

Rob

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

心凉怎暖 2024-07-14 15:24:01

这是 ASP.NET 配置的层次结构。 也许这可以帮助理解哪些设置会相互覆盖。

服务器

Machine.config:Machine.config 文件包含服务器上所有 Web 应用程序的 ASP.NET 架构。 该文件位于配置合并层次结构的顶部。

根 Web

Web.config:服务器的 Web.config 文件与 Machine.config 文件存储在同一目录中,并包含大多数 system.web 配置部分的默认值。 在运行时,该文件将被合并到配置层次结构中从顶部开始的第二个文件。

网站

Web.config:特定网站的 Web.config 文件包含适用于该网站并通过该网站的所有 ASP.NET 应用程序和子目录向下继承的设置。

ASP.NET 应用程序根目录

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

ASP.NET 应用程序子目录

Web.config:应用程序子目录的 Web.config 文件包含适用于该子目录的设置,并向下继承其分支中的所有子目录。

客户端应用程序目录

ApplicationName.config:ApplicationName.config 文件包含 Windows 客户端应用程序(不是 Web 应用程序)的设置。


了解哪些 ASP.NET 文件和文件夹是通过文件夹和应用程序继承的对于开发和故障排除非常重要。

以下是一个简短的摘要:

  • web.config 文件沿树一路继承,超越所有应用程序边界。
  • global.asax 仅存在于其应用程序
  • /bin 中,而 /app_{folders} 仅存在于其应用程序中

因此,这意味着根 web.config 文件中设置的任何内容都将继承整个站点,即使某些文件夹被标记为应用程序。

如果 web.config 文件包含对程序集的引用,但子应用程序没有这些程序集,则情况会变得混乱。 例如,假设您在站点的根目录中配置了一个 HTTP 模块,并从站点 web.config 文件中引用。 如果您有一个名为 /subfolder 的子应用程序,该子应用程序被标记为应用程序,则 /subfolder 将尝试从 /subfolder/bin 加载 HTTP 处理程序。 由于它不存在,因此会抛出错误。

有多种方法可以解决这个问题。 如果 /subfolder 中不需要 HTTP 处理程序,最干净的方法可能是通过在 /subfolder/web.config 文件中添加子句来“删除”引用。 您可以使用 来执行此操作。 以下是如何删除子文件夹中的 HTTP 模块的示例:

<httpModules>
  <remove name="ErrorLog"/>
</httpModules>

站点 web.config 可能如下所示:

<httpModules>
      <add name="ErrorLog"  type="GotDotNet.Elmah.ErrorLogModule, GotDotNet.Elmah, Version=1.0.5527.0, Culture=neutral, PublicKeyToken=978d5e1bd64b33e5" />
</httpModules>print("code sample");

This is the hierarchy for ASP.NET configuration. Maybe this could help understanding which settings overwrite each other.

Server

Machine.config: The Machine.config file contains the ASP.NET schema for all of the Web applications on the server. This file is at the top of the configuration merge hierarchy.

Root Web

Web.config: The Web.config file for the server is stored in the same directory as the Machine.config file and contains default values for most of the system.web configuration sections. At run time, this file is merged second from the top in the configuration hierarchy.

Web site

Web.config: The Web.config file for a specific Web site contains settings that apply to the Web site and inherit downward through all of the ASP.NET applications and subdirectories of the site.

ASP.NET application root directory

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.

ASP.NET application subdirectory

Web.config: The Web.config file for an application subdirectory contains settings that apply to this subdirectory and inherit downward through all of the subdirectories in its branch.

Client application directory

ApplicationName.config: The ApplicationName.config file contains settings for a Windows client application (not a Web application).


Understanding which ASP.NET files and folders are inherited through folders and applications is very important for development and troubleshooting.

Here is a short summary:

  • web.config files inherit all the way down the tree, past all application boundaries.
  • global.asax only lives within its application
  • /bin and the /app_{folders} only live within their application

So, this means that anything set in the root web.config file will inherit down the entire site, even if some folders are marked as applications.

Where this gets messy is if the web.config file has references to assemblies but sub-applications don't have those assemblies. For example, let's say that you have a HTTP Module configured in the root of the site and referenced from the site web.config file. If you have a sub-application called /subfolder which is marked as an application, then /subfolder will attempt to load the HTTP Handler from /subfolder/bin. Since it doesn't exist, an error will be thrown.

There are multiple ways around this. Probably the cleanest if the HTTP Handler isn't needed in /subfolder is by 'removing' the reference by adding a clause in the /subfolder/web.config file. You can do this with . Here is an example of how to remove a HTTP Module in a subfolder:

<httpModules>
  <remove name="ErrorLog"/>
</httpModules>

Here is what the site web.config might look like:

<httpModules>
      <add name="ErrorLog"  type="GotDotNet.Elmah.ErrorLogModule, GotDotNet.Elmah, Version=1.0.5527.0, Culture=neutral, PublicKeyToken=978d5e1bd64b33e5" />
</httpModules>print("code sample");
娇纵 2024-07-14 15:24:01

根据您在评论中所说的内容,我建议采用“尝试和错误”。

如果您故意插入错误的条目,会发生什么情况? 应用程序失败还是没有影响任何事情?

尝试复制内容,然后删除并从头开始重新创建该文件。

From what you tell in the comments, I suggest going with "Try and Error".

What happens, if you insert an erroneous entry by purpose? Does the application fail or doesn't that affect anything?

Try to copy the content and then delete and recreate that file from scratch.

污味仙女 2024-07-14 15:24:01

首先非常感谢各位热心解答的朋友,非常感谢你们的帮助!

只是关于这个问题的更新。 这是一场艰难的比赛!

事实证明,代码或配置没有任何问题。

服务器场似乎发生了一些奇怪的事情(我完全无法控制或访问)。
系统管理员重建了场,重新部署了解决方案,一切正常。

我想我们永远不会知道出了什么问题,但至少我们知道这不是开发问题!

再次感谢,

First off, thank you very much to the guys that answered, I do appreciate the help!

Just an update on this issue. It was a tough one!

Turns out, there was nothing wrong with the code, or the configuration.

It appears that something weird was going on with the server farm (which I have absolutely no control over or access to).
The sysadmin re-built the farm, re-deployed the solution and all worked fine.

I guess we will never know what was wrong, but at least we know it was not a development issue!

Thanks again,
Rob

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文