我正在尝试将带有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>
答案 0 :(得分:1)
我终于找到了这个问题。我的子应用程序是2级深度。不幸的是,在这种情况下,IIS Express并不像完全成熟的IIS那样。即使它们被配置为应用程序,IIS Express也没有读取其配置文件。我必须为allowSubDirConfig属性设置为true的父文件夹显式添加虚拟目录配置。
<virtualDirectory path="/Services" allowSubDirConfig="true" />