3

我正在尝试将带有 WCF 服务的 MVC3 应用程序作为子应用程序在 IIS Express 中按预期工作。它在 IIS 中运行良好,但在 IIS Express 中却做了一些奇怪的事情。

当我在 IIS 中运行站点时,子应用程序和父应用程序的配置设置在子应用程序中都可用。但是,当我在 IIS Express 中运行相同的代码时,只有父配置设置可用。

我找不到任何关于这是预期行为的文档。这并不排除它,但我倾向于怀疑我有配置问题。

问题是,如何在 IIS Express 中运行这些站点而不会丢失在子应用程序中应用的设置?

我正在使用带有 Visual Studio 2010、MVC3 和 IIS Express 8 的 Windows 7 机器。

这是我的 applicationhost.config 文件中的站点配置。

<site name="ParentMvcApp" id="7">
    <application path="/" applicationPool="Clr4IntegratedAppPool">
        <virtualDirectory path="/" physicalPath="c:\users\<username>\documents\visual studio 2010\Projects\ChildAppTest\ParentMvcApp" />
    </application>
    <application path="/Services/ChildWcfApp" applicationPool="Clr4IntegratedAppPool">
        <virtualDirectory path="/" physicalPath="c:\users\<username>\documents\visual studio 2010\Projects\ChildAppTest\ChildWcfApp" />
    </application>
    <bindings>
        <binding protocol="http" bindingInformation="*:33888:localhost" />
    </bindings>
</site>

这是 MVC 配置文件的内容。

<configuration>
  <appSettings>
    <add key="webpages:Version" value="1.0.0.0"/>
    <add key="ClientValidationEnabled" value="true"/>
    <add key="UnobtrusiveJavaScriptEnabled" value="true"/>
  </appSettings>

  <system.web>
    <compilation debug="true" targetFramework="4.0">
      <assemblies>
        <add assembly="System.Web.Abstractions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
        <add assembly="System.Web.Helpers, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
        <add assembly="System.Web.Routing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
        <add assembly="System.Web.Mvc, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
        <add assembly="System.Web.WebPages, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
      </assemblies>
    </compilation>

    <authentication mode="Forms">
      <forms loginUrl="~/Account/LogOn" timeout="2880" />
    </authentication>

    <pages>
      <namespaces>
        <add namespace="System.Web.Helpers" />
        <add namespace="System.Web.Mvc" />
        <add namespace="System.Web.Mvc.Ajax" />
        <add namespace="System.Web.Mvc.Html" />
        <add namespace="System.Web.Routing" />
        <add namespace="System.Web.WebPages"/>
      </namespaces>
    </pages>
  </system.web>

  <system.webServer>
    <validation validateIntegratedModeConfiguration="false"/>
    <modules runAllManagedModulesForAllRequests="true"/>
  </system.webServer>

  <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" />
        <bindingRedirect oldVersion="1.0.0.0-2.0.0.0" newVersion="3.0.0.0" />
      </dependentAssembly>
    </assemblyBinding>
  </runtime>
  <system.serviceModel>
    <bindings>
      <basicHttpBinding>
        <binding name="BasicHttpBinding_IService1" />
      </basicHttpBinding>
    </bindings>
    <client>
      <endpoint address="http://localhost:33888/Services/ChildWcfApp/Service1.svc" binding="basicHttpBinding"
        bindingConfiguration="BasicHttpBinding_IService1" contract="ServiceReference1.IService1"
        name="BasicHttpBinding_IService1" />
    </client>
  </system.serviceModel>
</configuration>

这是 WCF 服务配置文件的内容。

<?xml version="1.0"?>
<configuration>
    <appSettings>
        <add key="Test"
             value="Wtf"/>
    </appSettings>
  <system.web>
    <compilation debug="true" targetFramework="4.0" />
  </system.web>
  <system.serviceModel>
    <behaviors>
      <serviceBehaviors>
        <behavior>
          <!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment -->
          <serviceMetadata httpGetEnabled="true"/>
          <!-- To receive exception details in faults for debugging purposes, set the value below to true.  Set to false before deployment to avoid disclosing exception information -->
          <serviceDebug includeExceptionDetailInFaults="false"/>
        </behavior>
      </serviceBehaviors>
    </behaviors>
    <serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
  </system.serviceModel>
 <system.webServer>
    <modules runAllManagedModulesForAllRequests="true"/>
  </system.webServer>

</configuration>
4

1 回答 1

1

我终于找到了问题。我的子应用程序有 2 个级别。不幸的是,在这种情况下,IIS Express 不像成熟的 IIS。即使它们被配置为应用程序,IIS Express 也不会读取它们的配置文件。我必须为将 allowSubDirConfig 属性设置为 true 的父文件夹显式添加虚拟目录配置。

<virtualDirectory path="/Services" allowSubDirConfig="true" />
于 2013-11-19T21:12:37.427 回答