Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/elixir/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Asp.net mvc 将MVC2应用程序添加到IIS 7中的站点_Asp.net Mvc_Iis_Asp.net Mvc 2_Iis 7_Nancy - Fatal编程技术网

Asp.net mvc 将MVC2应用程序添加到IIS 7中的站点

Asp.net mvc 将MVC2应用程序添加到IIS 7中的站点,asp.net-mvc,iis,asp.net-mvc-2,iis-7,nancy,Asp.net Mvc,Iis,Asp.net Mvc 2,Iis 7,Nancy,在IIS7中,我使用Nancy项目创建了一个网站。然后,我使用别名api向站点添加了一个mvc2应用程序。我能够完美地访问Nancy项目中定义的路线。但是,当我访问/api时,我得到以下错误: Could not load type 'Nancy.Hosting.Aspnet.NancyHttpRequestHandler'. Description: An unhandled exception occurred during the execution of the current web

在IIS7中,我使用Nancy项目创建了一个网站。然后,我使用别名
api
向站点添加了一个mvc2应用程序。我能够完美地访问Nancy项目中定义的路线。但是,当我访问
/api
时,我得到以下错误:

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
MVC2应用程序似乎试图使用NancyHttpRequestHandler来处理请求。我这样说是因为Nancy应用程序中未定义的路由显示404页面

我试过几种方法:

  • 为了MVC2应用程序的
    Web.config
    ,我在
    块中添加了以下内容:

    <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>
    
    <httpHandlers>
      <add verb="*" type="Nancy.Hosting.Aspnet.NancyHttpRequestHandler" path="*" />
      <remove verb="*" path="api/*" />
    </httpHandlers>
    
  • 我还尝试在这两个应用程序中玩弄
    块中的设置

  • 当MVC2应用程序嵌入IIS 7中的Nancy站点时,如何使其正常运行?任何指导都将不胜感激。

    您的想法是正确的——您需要阻止NancyFx特定配置部分继承到子MVC站点

    在root(NancyFx)站点中,使用正常配置创建一个
    标记。您的NancyFx web.config结构如下所示。(如果您决定将MVC2站点升级为MVC3,我添加了一些注释,以避免您遇到麻烦。)


    太棒了!刚刚测试过这个,效果很好。如果我能说服我的团队将过去两周的所有MVC3工作迁移到Nancy就好了。:)谢谢你提供的信息。干杯
    <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>