configSource 文件“connections.config”也用于父级,这是不允许的。

Qua*_*ary 9 iis asp.net iis-7.5 web.config

题:

我面临以下情况:

部署在机器“vmsomething”上的 ASP.NET .NET 4.0 Web 应用程序。

在 IIS 7.5 上运行的 Web 应用程序驻留在 vmsomething 上的 d:\webs\myapplication 中。

应用程序的配置文件:

连接.config

<?xml version="1.0"?>
<connectionStrings>
  <remove name="server"/>
  <add name="server" connectionString="Data Source=OUR_DB_Server;Initial Catalog=MY_INITIAL_CATALOG;Persist Security Info=False;User Id=OUR_DB_User;Password=OUR_TOP_SECRET_PASSWORD;MultipleActiveResultSets=False;Packet Size=4096;Application Name=&quot;MyApplication&quot;" providerName="System.Data.SqlClient"/>
</connectionStrings>
Run Code Online (Sandbox Code Playgroud)

网络配置:

<?xml version="1.0"?>
<configuration>

  <connectionStrings configSource="connections.config"/>

  <system.web>
    <roleManager enabled="true" defaultProvider="AspNetWindowsTokenRoleProvider"/>
    <compilation strict="true" explicit="true">
      <assemblies>
        <add assembly="System.DirectoryServices, Version=2.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A"/>
        <add assembly="Microsoft.JScript, Version=8.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A"/>
      </assemblies>
    </compilation>
    <authentication mode="Windows"/>
    <pages>
      <namespaces>
        <clear/>
        <add namespace="System"/>
      </namespaces>
    </pages>
    <customErrors mode="Off">
      <error statusCode="404" redirect="~/w8/index.html"/>
    </customErrors>
    <globalization uiCulture="de" culture="de-CH" requestEncoding="UTF-8" responseEncoding="UTF-8"/>
    <httpRuntime maxRequestLength="2048000" executionTimeout="86400"/>
  </system.web>
  <system.webServer>
    <validation validateIntegratedModeConfiguration="false"/>
  </system.webServer>
</configuration>
Run Code Online (Sandbox Code Playgroud)

那么可以通过两种方式访问​​应用程序:
方法一:http : //vmsomething.com
方法二:http : //vmsomething.com/my_application_virtdir
(没有.com,不能添加本地链接)

现在我可以在http://vmsomething.com上打开应用程序就好了。
如果我尝试在http://vmsomething.com/my_application_virtdir上打开应用程序,我会收到此错误:

配置错误

我不是服务器的管理员,也不知道他是怎么配置的。
现在我的问题:

  • 是什么导致了这个错误?
  • 如何解决?

小智 9

原因是您有两个针对同一个物理文件夹的网站。并且在 web.config 中存在继承

http://vmsomething是父母,http://vmsomething/my_application_virtdir是它的孩子。子 web.config 从其父级继承所有元素。并且 web.config 通常不是为在这种情况下工作而设计的。当从 nuget 安装的其他实用程序尝试修改您的 web.config 时,您可能会遇到很多麻烦。

如果您想在http://vmsomething/my_application_virtdir那时访问您的网站,我想最简单的解决方案是将物理路径更改为http://vmsomething不同的内容。

如果您想在不指定 virtdir 的情况下测试您的网站如何工作,您可以在 IIS 中配置一个单独的网站(不是默认网站)并将其定位到相同的物理路径。然后,您将能够同时测试两种部署方式。