ASP.NET、计算机级 web.config 和位置元素的问题

发布于 2024-08-28 13:11:08 字数 1425 浏览 3 评论 0原文

我有一台运行 Windows Web Server 2008 R2 的服务器。机器级 web.config 具有以下条目:

<location path="Preview">
    <appSettings>
        <add key="Environment" value="Preview" />
    </appSettings>
</location>

<location path="Staging">
    <appSettings>
        <add key="Environment" value="Staging" />
    </appSettings>
</location>

<location path="Production">
    <appSettings>
        <add key="Environment" value="Production" />
    </appSettings>
</location>

我有一个在 D:\Sites\Preview\ 方向设置的网站,因此完整路径为 D :\Sites\Preview\WebSite1。如果我放置一个仅输出 ConfigurationManager.AppSettings["Environment"] 值的简单 aspx 文件,它会显示值 Preview

我不清楚它到底是如何工作的,但确实如此。我几周前就设置好了,现在尝试复制它 - 我将第二个站点放在 D:\Sites\Preview\ 目录中,期望它会自动选择适当的站点appSettings 条目,但由于某种原因它没有 - 相同的 aspx 页面不显示任何内容。

此外,当我进入 IIS 管理器并打开配置编辑器时,其中没有任何设置,而列出了第一个站点的设置。

关于我可能会错过什么有什么想法吗?位置元素是否打算像这样工作,或者我只是在我的第一个网站中发现了一些神奇的侥幸?


更新:

我配置的网站的实际名称是:

  • Preview.Wishinator in D:\Sites\Preview\DanDoes.Wishinator.Site (这是有效的)
  • Preview.ShowRoom in D:\Sites\Preview\DanDoes.ShowRoom (无效)
  • TestD:\Sites\Preview\Test 中(不起作用)

I've got a server running Windows Web Server 2008 R2. The machine-level web.config has the following entries:

<location path="Preview">
    <appSettings>
        <add key="Environment" value="Preview" />
    </appSettings>
</location>

<location path="Staging">
    <appSettings>
        <add key="Environment" value="Staging" />
    </appSettings>
</location>

<location path="Production">
    <appSettings>
        <add key="Environment" value="Production" />
    </appSettings>
</location>

I have a website that I'd set up in the direction D:\Sites\Preview\, so the full path would be D:\Sites\Preview\WebSite1. If I put a simple aspx file that just outputs the value of ConfigurationManager.AppSettings["Environment"], it displays the value Preview.

I'm not clear on exactly how that works, but it does. I'd set this up several weeks ago, and just now tried to duplicate this - I put a second site in the D:\Sites\Preview\ directory, expecting that it would automatically pick up the appropriate appSettings entries, but for some reason it hasn't - the same aspx page doesn't show anything.

Additionally, when I go into the IIS manager and open the Configuration Editor, there are no settings in there, whereas there are settings listed for the first site.

Any ideas as to what I could be missing? Is the location element intended to work like this, or did I just find some magical fluke with my first site?


UPDATE:

The actual names of the web sites I've configured are:

  • Preview.Wishinator in D:\Sites\Preview\DanDoes.Wishinator.Site (this is the one that works)
  • Preview.ShowRoom in D:\Sites\Preview\DanDoes.ShowRoom (does not work)
  • Test in D:\Sites\Preview\Test (does not work)

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

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

发布评论

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

评论(1

悲喜皆因你 2024-09-04 13:11:08

上面的位置标记应该与 IIS 中的站点名称匹配,以使其正确匹配,因此我的猜测是 \Preview\WebSite1 中的站点在 IIS 中被命名为“Preview”。

总而言之,匹配不是通过文件夹名称进行的,而是通过 IIS 中配置的“站点名称”进行的。

The location tags above should match the Site Name in IIS to make it match correctly, so my guess is that your site in \Preview\WebSite1 was named in IIS "Preview".

So to summarize the match is not made by folder name but made by the "Site Name" that is configured in IIS.

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