简体   繁体   English

IIS7的ASP MVC路由问题

[英]ASP MVC routing problem with IIS7

We discovered problem when deploying MVC application on IIS7 server: any route navigation gives 404 error. 我们在IIS7服务器上部署MVC应用程序时发现问题:任何路由导航都会出现404错误。 I've found on web that problem can be solved by setting application pool managed pipeline mode to integrated, but now we have exception: 我在网上发现可以通过将应用程序池管理的管道模式设置为集成来解决问题,但现在我们有例外:

Request is not available in this context

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: Request is not available in this context

Source Error: 


Line 19: 
Line 20:         public override void SetActiveUser(Guid userOid) {
Line 21:             FormsAuthentication.SignOut();
Line 22:             HttpContext.Current.Items[Key] = userOid.ToString();
Line 23:             FormsAuthentication.RedirectFromLoginPage(userOid.ToString(), true); 

Does anybody have any ideas? 有人有什么想法吗?

The problem is probably in the web.config file. 问题可能出在web.config文件中。 Since IIS7 there is now two places to configure handlers and modules. 从IIS7开始,现在有两个地方可以配置处理程序和模块。 When you run in classic mode, is like running on IIS 6 (though under IIS7). 当您在经典模式下运行时,就像在IIS 6上运行一样(尽管在IIS7下)。

Here is the config file: 这是配置文件:

<system.web>
[...]
    <httpHandlers>
            [...]
        </httpHandlers>
        <httpModules>
            [...]
            <add name="UrlRoutingModule" type="System.Web.Routing.UrlRoutingModule, System.Web.Routing, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />

        </httpModules>
    </system.web>

there should be only IIS 6 configurations. 应该只有IIS 6配置。

IIS 7 config should be placed under: IIS 7配置应放在:

    <system.webServer>
[...]
            <modules runAllManagedModulesForAllRequests="true" >
                <remove name="UrlRoutingModule"/>
                <add name="UrlRoutingModule" type="System.Web.Routing.UrlRoutingModule, System.Web.Routing, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
            </modules>
            <handlers>
                <add name="UrlRoutingHandler" preCondition="integratedMode" verb="*" path="UrlRouting.axd" type="System.Web.HttpForbiddenHandler, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
            </handlers>
        </system.webServer>

To glom onto what kvalcanti stated. 要了解kvalcanti所说的话。 The standard routing was designed for IIS 7. There is a kludge added for older versions of IIS. 标准路由是为IIS 7设计的。为旧版本的IIS添加了一个kludge。 So, if you are deving on older versions, you have the kludged up version of the config file. 因此,如果您在旧版本上付费,那么您就拥有配置文件的kludged版本。 Changing the config solves the issue. 更改配置可以解决问题。

In addition to what kvalcanti mentions, there is a possibility you have a bit of a kludge set up in your global.asax, as well. 除了kvalcanti提到的内容之外,你的global.asax中也有可能设置一些kludge。 I am not sure it is still mandatory in the newest version of ASP.NET MVC, or not, as I have not deved on anything but Vista in the last few months. 我不确定在最新版本的ASP.NET MVC中它是否仍然是强制性的,因为在过去的几个月中我没有在Vista之外的任何东西。

This post has some insight: http://www.developingfor.net/aspnet-mvc/deploying-aspnet-mvc-on-iis6.html 这篇文章有一些见解: http//www.developingfor.net/aspnet-mvc/deploying-aspnet-mvc-on-iis6.html

Scott Guthrie had a great blog post about this on his blog ( http://weblogs.asp.net/scottgu/ ), but I don't have it bookmarked. Scott Guthrie在他的博客( http://weblogs.asp.net/scottgu/ )上有一篇关于这篇文章的博文,但我没有给它添加书签。

  1. Open Nuget 打开Nuget
  2. Install NotFoundMvc 安装NotFoundMvc
  3. ??? ???
  4. Profit 利润

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM