微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

asp.net – 与IIS7的ASP MVC路由问题

我们在IIS7服务器上部署MVC应用程序时发现问题:任何路由导航都会出现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);

有人有什么想法吗?

解决方法

问题可能出在web.config文件中.从IIS7开始,现在有两个地方可以配置处理程序和模块.当您在经典模式下运行时,就像在IIS 6上运行一样(尽管在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,PublicKeyToken=31BF3856AD364E35" />
            </modules>
            <handlers>
                <add name="UrlRoutingHandler" preCondition="integratedMode" verb="*" path="UrlRouting.axd" type="System.Web.httpforbiddenhandler,System.Web,Version=2.0.0.0,PublicKeyToken=b03f5f7f11d50a3a" />
            </handlers>
        </system.webServer>

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐