关于使用在webforms里使用routing遇到的问题

本文介绍在不同IIS模式下配置ASP.NET路由的方法。包括在Web.config文件中添加路由组件、根据IIS版本选择配置模块等步骤。对于IIS7集成模式,需特别注意模块与处理器的配置。

看了重典的两篇文章

System.Web.Routing入门及进阶 上篇

System.Web.Routing入门及进阶 下篇

仿照其中的进行了操作,发现怎么不都起作用,非常奇怪,搜了好多才找到了解决方案

是在MSDN上找到的,如下:

To configure an ASP.NET Web site project for routing

 

  1. In the application's Web.config file, add the ASP.NET routing assembly to the assemblies element, as shown in the following example:

    <add assembly="System.Web.Routing, Version=3.5.0.0,
        Culture=neutral,
        PublicKeyToken=31BF3856AD364E35"/>
        
  2. If the application runs under IIS 6.0 or IIS 7.0 Classic mode, add the UrlRoutingModule class to the httpModules element, as shown in the following example:

    <httpModules>
        <add name="UrlRoutingModule"
        type="System.Web.Routing.UrlRoutingModule,
        System.Web.Routing,
        Version=3.5.0.0,
        Culture=neutral,
        PublicKeyToken=31BF3856AD364E35"/>
        </httpModules>
        
  3. If the application runs under IIS 7.0 Integrated mode, add the UrlRoutingModule class to the modules element, as shown in the following example:

    <system.webServer>
        <modules>
        <remove name="UrlRoutingModule" />
        <add name="UrlRoutingModule"
        type="System.Web.Routing.UrlRoutingModule,
        System.Web.Routing,
        Version=3.5.0.0,
        Culture=neutral,
        PublicKeyToken=31BF3856AD364E35"/>
        </modules>
        </system.webServer>
        
  4. If the application runs under IIS 7.0 Integrated mode, add the UrlRoutingHandler class to the handlers element as shown in the following example:

    <system.webServer>
        <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>
        

需要在web.config中进行以上配置

一般的教程中只提到了1和2

1是必须的,而2是针对IIS的经典模式的

而我用的是IIS7的集成模式

所以需要进行3和4的配置,按照3和4进行了操作以后

就成功了!

转载于:https://www.cnblogs.com/zhangrou/archive/2009/01/18/1377985.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值