ASP MVC在IIS7上的路由问题

5
我们在部署MVC应用程序到IIS7服务器时发现了问题:任何路由导航都会出现404错误。我在网上发现,可以通过将应用程序池托管管道模式设置为集成来解决问题,但现在我们遇到了异常:
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); 

有人有任何想法吗?

3个回答

10

问题可能出现在web.config文件中。自IIS7以来,现在有两个地方可以配置处理程序和模块。当您在经典模式下运行时,就像在IIS6上运行一样(尽管在IIS7下)。

这是配置文件:

<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>

应该只有IIS 6配置。

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>

1

借鉴kvalcanti的说法,标准路由是为IIS 7设计的,而旧版本的IIS中添加了一些应急措施。所以,在旧版本上开发时,你会面对一种应急措施的配置文件。更改配置文件就可以解决这个问题。

除了kvalcanti提到的内容,全局.asax中也可能设置了一些应急措施。我不确定在最新版本的ASP.NET MVC中是否仍然需要,因为过去几个月里我只在Vista上进行了开发。

这篇文章提供了一些洞见:http://www.developingfor.net/aspnet-mvc/deploying-aspnet-mvc-on-iis6.html

Scott Guthrie在他的博客(http://weblogs.asp.net/scottgu/)上有一篇很好的关于这个主题的博客文章,但我没有收藏。


-1

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接