2012-08-15 131 views
6

添加到南希的網站在IIS 7中,我創建了使用南希項目網站。然後,我添加了一個MVC 2應用程序使用別名api網站。我能夠完美地訪問Nancy項目中定義的路線。然而,當我訪問/api,我得到以下錯誤:的MVC 2應用程序在IIS 7

Could not load type 'Nancy.Hosting.Aspnet.NancyHttpRequestHandler'. 

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 

Exception Details: System.Web.HttpException: Could not load type 'Nancy.Hosting.Aspnet.NancyHttpRequestHandler'. 

Source Error: 

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below. 

Stack Trace: 

[HttpException (0x80004005): Could not load type 'Nancy.Hosting.Aspnet.NancyHttpRequestHandler'.] 
    System.Web.Compilation.BuildManager.GetType(String typeName, Boolean throwOnError, Boolean ignoreCase) +11588073 
    System.Web.Configuration.HandlerFactoryCache.GetTypeWithAssert(String type) +47 
    System.Web.Configuration.HandlerFactoryCache.GetHandlerType(String type) +18 
    System.Web.Configuration.HandlerFactoryCache..ctor(String type) +27 
    System.Web.HttpApplication.GetFactory(String type) +95 
    System.Web.MaterializeHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +352 
    System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +375 

看來,MVC 2應用程序試圖使用NancyHttpRequestHandler來處理請求。我這樣說是因爲Nancy應用程序中未定義的路由顯示404頁面。

我已經試過幾件事情:

  1. 到MVC 2應用程序的Web.config,我添加了以下到<system.web/>塊:

    <httpHandlers> 
        <add verb="*" path="*.mvc" validate="false" type="System.Web.Mvc.MvcHttpHandler, System.Web.Mvc, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" /> 
    </httpHandlers> 
    
  2. 南錫應用Web.config,我加下面對<system.web/>塊:

    <httpHandlers> 
        <add verb="*" type="Nancy.Hosting.Aspnet.NancyHttpRequestHandler" path="*" /> 
        <remove verb="*" path="api/*" /> 
    </httpHandlers> 
    
  3. 我也試圖與這兩個應用程序的<system.webServer/><system.serviceModel/>塊的設置玩弄。

如何在MVC 2應用程序嵌入到IIS 7中的Nancy站點時正常運行?任何指導將不勝感激。

回答

1

您有正確的想法 - 您需要阻止NancyFx特定配置部分繼承到子MVC站點。

在你的根(NancyFx)網站,創建一個<location/>標籤與您的正常配置。您的NancyFx web.config結構將如下所示。 (我加了註釋,試圖讓你擺脫困境,如果你決定升級你的MVC2網站MVC3。)

<configuration> 
    <configSections/> 
    <!-- FYI... configSections cannot be moved into the location tag. If you plan 
     to upgrade to MVC3 and use the Razor view engine, those configSection 
     declarations need to live here. If you upgrade to MVC3 and use the Razor 
     view engine, you will need to remove the Razor configSections from the 
     views/web.config files any child MVC3 project. --> 
    <system.web /> <!-- site-wide system.web settings --> 
    <system.webServer /> <!-- site-wide system.webServer settings --> 

    <!-- Put the NancyFx specific configuration here --> 
    <location path="." inheritInChildApplications="false"> 
    <!-- The inheritInChildApplications attribute is the magic sauce! :) --> 
    <connectionStrings /> 
    <!-- If the connectionStrings are shared by the child site, 
     you could move them out to the main configuration. But they 
     cannot exist in both sections of this file. --> 
    <appSettings /> 
    <system.web> 
     <httpHandlers> 
     <add verb="*" type="Nancy.Hosting.Aspnet.NancyHttpRequestHandler" path="*" /> 
     </httpHandlers> 
    </system.web> 
    <system.webServer> 
     <handlers> 
     <add name="Nancy" verb="*" type="Nancy.Hosting.Aspnet.NancyHttpRequestHandler" path="*" /> 
     </handlers> 
    </system.webServer> 
    </location> 
</configuration> 
+0

好極了!只是測試了這一點,它就像一個魅力。如果我能說服我的團隊從過去兩週南希遷移我們所有的工作MVC3。 :) 感謝您的信息。乾杯! – 2012-09-07 18:24:24

相關問題