加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > asp.Net > 正文

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

发布时间:2020-12-16 03:31:55 所属栏目:asp.Net 来源:网络整理
导读:我们在IIS7服务器上部署MVC应用程序时发现问题:任何路由导航都会出现404错误.我在网上发现可以通过将应用程序池管理的管道模式设置为集成来解决问题,但现在我们有例外: Request is not available in this contextDescription: An unhandled exception occu
我们在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>

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读