2012-08-15 5 views
6

In IIS 7, ho creato un sito Web utilizzando un progetto Nancy. Quindi, ho aggiunto un'applicazione MVC 2 al sito utilizzando l'alias api. Sono in grado di visitare perfettamente i percorsi definiti nel progetto Nancy. Tuttavia, durante la mia visita /api, ottengo il seguente errore:Aggiungere un'applicazione MVC 2 a un sito Nancy in 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 

Sembra che l'applicazione MVC 2 sta tentando di utilizzare la NancyHttpRequestHandler per elaborare la richiesta. Dico questo perché i percorsi che non sono definiti nell'applicazione Nancy visualizzano una pagina 404.

ho provato diverse cose:

  1. Per Web.config dell'applicazione MVC 2, ho aggiunti il ​​seguente al blocco <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. Per Web.config di applicazione Nancy, ho aggiunto il seguente al blocco <system.web/>:

    <httpHandlers> 
        <add verb="*" type="Nancy.Hosting.Aspnet.NancyHttpRequestHandler" path="*" /> 
        <remove verb="*" path="api/*" /> 
    </httpHandlers> 
    
  3. Ho anche provato a giocare con le impostazioni nei blocchi <system.webServer/> e <system.serviceModel/> in entrambe le applicazioni.

Come posso ottenere il corretto funzionamento dell'applicazione MVC 2 quando è incorporato nel sito di Nancy in IIS 7? Qualsiasi suggerimento sarebbe davvero apprezzato.

risposta

1

Hai avuto l'idea giusta: devi bloccare l'ereditarietà delle sezioni di configurazione specifiche di NancyFx nei siti MVC secondari.

Nel sito radice (NancyFx), creare un tag <location/> con la configurazione normale. La tua struttura web.config di NancyFx avrà un aspetto simile al seguente. (Ho aggiunto commenti per cercare di tenervi fuori dai guai se decidete di aggiornare il vostro sito MVC2 a 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

Eccellente! Ho appena provato questo e funziona come un fascino. Se solo potessi convincere la mia squadra a migrare tutto il nostro lavoro MVC3 dalle ultime due settimane a Nancy. :) Grazie per l'informazione. Saluti! –

Problemi correlati