IIS URL Rewriting and ASP.NET Routing

With the release of the URL Rewrite Module for IIS and the inclusion of ASP.NET routing into the .NET Framework 4, there have been a lot of questions from ASP.NET developers about how these two features relate to each other and when you should use one or the other. This document describes the differences between these two technologies and provides guidance for Web developers about when to use IIS URL rewriting and when to use ASP.NET routing.

From a high-level perspective, it seems like these technologies provide very similar functionality--both allow your Web applications to have user-friendly and search-engine-friendly URLs.

However, there are fundamental differences between these two technologies that are important to understand to make the right decision about what to use for your Web application.

To help you understand those differences, we will first explain how IIS URL rewriting and ASP.NET routing work.

Differences Between IIS URL Rewriting and ASP.NET Routing

Based on the above explanation, there are the following main conceptual differences between IIS URL rewriting and ASP.NET routing:

  1. URL rewriting is used to manipulate URL paths before the request is handled by the Web server. The URL rewriting module does not know which handler will eventually process the rewritten URL. In addition, the actual request handler might not know that the URL has been rewritten.
  2. ASP.NET routing is used to dispatch a request to a handler based on the requested URL path. As opposed to URL rewriting, the routing module knows about the handlers and selects the handler that should generate a response for the requested URL. You can think of ASP.NET routing as an advanced handler-mapping mechanism.

In addition to these conceptual differences, there are the following functional differences between IIS URL rewriting and ASP.NET routing:

  1. The IIS URL Rewrite module can be used with any type of Web application, which includes ASP.NET, PHP, ASP, and static files. ASP.NET routing can be used only with .NET Framework-based Web applications.
  2. The IIS URL Rewrite module works the same way regardless of whether integrated or classic IIS pipeline mode is used for the application pool. For ASP.NET routing, it is preferable to use integrated pipeline mode. ASP.NET routing can work in classic mode, but in that case the application URLs must include file name extensions or the application must be configured to use "*" handler mapping in IIS.
  3. The IIS URL Rewrite module can make rewriting decisions based on domain names, HTTP headers, and server variables. By default, ASP.NET routing works only with URL paths and with the HTTP-Method header.
  4. In addition to rewriting, the URL Rewrite module can perform HTTP redirection, issue custom status codes, and abort requests. ASP.NET routing does not perform these tasks.
  5. The URL Rewrite module is not extensible in its current version. ASP.NET routing is fully extensible and customizable.

Which Option Should You Use?

What does all this information mean if you need to choose a technology to enable clean URLs for your Web applications? In this section, we explain how to make this choice.

If your Web application is built by using anything except ASP.NET, use the IIS URL Rewrite module. Otherwise, the rules are:

  1. If you are developing a new ASP.NET Web application that uses either ASP.NET MVC or ASP.NET Dynamic Data technologies, use ASP.NET routing. Your application will benefit from native support for clean URLs, including generation of clean URLs for the links in your Web pages. Note that ASP.NET routing does not support standard Web Forms applications yet, although there are plans to support it in the future.
  2. If you already have a legacy ASP.NET Web application and do not want to change it, use the URL Rewrite module. The URL Rewrite module lets you translate search engine-friendly URLs into a format that your application currently uses. Also, it lets you create redirect rules that can be used to redirect search engine crawlers to clean URLs.

In practice, however, the choice does not have to be either/or. The technologies can be used together and can complement each other. In the following sections, we outline some scenarios where you can use ASP.NET routing and IIS URL rewriting together.

Enforcing canonical URLs for your application.
You should force the use of http://www.mysite.com/home/about instead of http://mysite.com/Home/About.
When a Web client requests a URL that does not conform to the format
that you want, the client is redirected to a canonical URL. In this
scenario, you can use the URL Rewrite module to enforce canonical URLs
and perform redirection, and use ASP.NET routing to select a handler
that would process the requested URL path.

Conclusion

Either IIS URL rewriting or ASP.NET routing can be used to implement URL manipulation scenarios for your Web application.

ASP.NET routing is a solution that is optimized for ASP.NET, thus it may be preferable for Web developers who design their ASP.NET applications from the ground up and want to have a clean URL structure.

IIS URL rewriting is a generic URL manipulation mechanism that addresses a multitude of scenarios.

In particular, it can be used by Web developers as well as Web server/site administrators to enable clean URLs for existing Web applications without modifying the application code.

IIS URL Rewriting and ASP.NET Routing的更多相关文章

  1. 001. Asp.Net Routing与MVC 之(基础知识):URL

    URL(Uniform Resoure Locator:统一资源定位器)是WWW页的绝对地址.URL地址格式排列为:scheme://host:port/path. 例如 http://www.zn. ...

  2. IIS URL Rewrite – Installation and Use

    IIS URL Rewrite – Installation and Use Posted by Nick LeFevre | Leave a reply IIS URL Rewrite Instal ...

  3. ASP.NET路由[ASP.NET Routing]

    ASP.NET路由[ASP.NET Routing] ASP.NET路由允许你在使用URL时不必匹配到网站中具体的文件,因为这个URL不必匹配到一个文件,你使用了描述用户行为且更容易被用户理解的URL ...

  4. ASP.NET Routing

    ASP.NET Routing Other Versions   ASP.NET routing enables you to use URLs that do not have to map to ...

  5. 003. Asp.Net Routing与MVC 之一: 请求如何到达MVC

    基础知识 本文用到的基础知识:URL.HttpModule 与 HttpHandler.IIS 的请求处理过程. URL HttpModule与HttpHandler IIS7.0的请求处理过程 OK ...

  6. .NET/ASP.NET Routing路由(深入解析路由系统架构原理)

    阅读目录: 1.开篇介绍 2.ASP.NET Routing 路由对象模型的位置 3.ASP.NET Routing 路由对象模型的入口 4.ASP.NET Routing 路由对象模型的内部结构 4 ...

  7. .NET/ASP.NET Routing路由(深入解析路由系统架构原理)http://wangqingpei557.blog.51cto.com/1009349/1312422

    阅读目录: 1.开篇介绍 2.ASP.NET Routing 路由对象模型的位置 3.ASP.NET Routing 路由对象模型的入口 4.ASP.NET Routing 路由对象模型的内部结构 4 ...

  8. NET/ASP.NET Routing路由(深入解析路由系统架构原理)(转载)

    NET/ASP.NET Routing路由(深入解析路由系统架构原理) 阅读目录: 1.开篇介绍 2.ASP.NET Routing 路由对象模型的位置 3.ASP.NET Routing 路由对象模 ...

  9. IIS 7.0 的 ASP.NET 应用程序生命周期概述(转载)

    IIS 7.0 的 ASP.NET 应用程序生命周期概述更新:2007 年 11 月本主题介绍在 IIS 7.0 集成模式下运行以及与 IIS 7.0 或更高版本一起运行的 ASP.NET 应用程序的 ...

随机推荐

  1. 一语道破Java 11的ZGC为何如此高效

    GC是大部分现代语言内置的特性,Java 11 新加入的ZGC号称可以达到10ms 以下的 GC 停顿,本文作者对这一新功能进行了深入解析.同时还对还对这一新功能带来的其他可能性做了展望.ZGC是否可 ...

  2. redo log和bin log

    讲redolog和binlog之前,先要讲一下一条mysql语句的执行过程. 1.client的写请求到达连接器,连接器负责管理连接.验证权限: 2.然后是分析器,负责复习语法,如果这条语句有执行过, ...

  3. 虚拟机VMware安装

    1.进入VMware官网,下载 (点击进入官网) 2.下载镜像文件 (点击进入官网下载) 3.下载好后,打开VMware,点击创建新的虚拟机 4.点击下一步,并找到刚才下载好的镜像文件 5.跟随系统点 ...

  4. Linux命令——finger

    简介 查询并显示系统用户的相关信息. 最小化安装Linux可能没有改名了,需要单独安装. RHEL/CentOS yum install finger* -y Ubuntu  apt-get inst ...

  5. 【DevOps】在CentOS中安装DockerCE

    准备 安装好CentOS7,拥有root账号密码,使用客户端登录. 安装 启动进入root用户,复制以下代码执行即可 yum install -y yum-utils device-mapper-pe ...

  6. VMware15 桥接模式无法上网

    1. 检查宿主机网络连接是否成功 2. 检查宿主机网络适配器列表是否有多余的 loop 等回环类型的适配器(楼主在安装npcap程序后系统出现回环类型的适配器,即把包发回本地,所有的虚拟机的桥接模式都 ...

  7. jquery-deferred应用

    我们说jquery1.5之后用的用deferred,那么deferred到底是个什么东西,看个例子 var wait = function(){ var task = function(){ cons ...

  8. 2星|项立刚《5G时代》:资料堆砌和一些假想设想,信息浓度太低

    “ 这是一本关于5G的书,但着眼点不是要说清楚5G的技术,因为解读5G技术的图书已经有很多,我自己也不是技术专家.本书是希望探讨在一个全新的网络体系下产业的发展与改变,以及5G对社会与经济的影响.P6 ...

  9. Mac---使用tree生成目录结构

    作为测试或者程序员,平时都有需求来生成目录树,进行项目层级的讲解等.如下是样式图: 实现方式,即操作步骤: Mac下使用 brew install tree 进行安装,安装后,在terminal中输入 ...

  10. springboot整合shiro引用配置文件配置redis信息报空指针异常

    1.问题现象: 上面这些属性是从application.properties配置文件中获取的,按常理来说应该能顺利获取到,但均未赋上值. 2.解决办法:(不得不说百度,千篇一律,最后用谷歌找到的) 最 ...