2

I would like to make my ASP.NET web page URLs without .aspx extensions. I can do it in two ways, use IIS7 URL Rewrite module or ASP.NET URL Routing. Which method to choose?

abatishchev
  • 98,240
  • 88
  • 296
  • 433
Tomas
  • 17,551
  • 43
  • 152
  • 257

1 Answers1

0

Use ASP.NET Routing. It's the most up-to-date and right way to do that, since .NET 4.0.

Read this thorough article regarding the subject written by the MSDN team (go to Which Option Should You Use?).

Routing keeps the request-resource resolution logic within your application, so it's very easy to add application-dependent logic when you need, and it eliminates the need to maintain synchronization between your application and a separate configuration resource.

Quote from the article mentioned above:

  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.

Also read this thorough answer in SO: IIS URL Rewriting vs URL Routing

Community
  • 1
  • 1
Ofer Zelig
  • 17,068
  • 9
  • 59
  • 93
  • While reading the article I found that in some cases I should use both technologies. For example I want to introduce "canonical URLs" rule for my app, as I understand from article it is not possible to do with ASP.NET Routing. – Tomas Sep 26 '11 at 07:46
  • It's possible but requires some work. Canonical URLs, when set in IIS URL Rewriting, only change URLs per-request, but does not change the source HTML. So if your HTML (.cshtml, .aspx) contains upper-case URLs for example, your server will get 2 hits - one with the upper-case URL and the _301 Moved Permanently_ that the URL Rewriting Module points to. It's very ineffiecient. – Ofer Zelig Sep 26 '11 at 07:52