JoanieBrar
JoanieBrar

Reputation: 151

performance rewrite rules vs routes.maproute

I'm helping a client with a web application upgrade, this includes a task that needs to route 100's of outdated bookmarks to new urls.

In reviewing the following links it seems clear cut that I should be updating the routing table and not putting in rewrite rules in web.config to deal with the outdated bookmarks:

When to use routes vs. rewrite rules?

http://www.iis.net/learn/extensions/url-rewrite-module/iis-url-rewriting-and-aspnet-routing

From a curiosity standpoint, it would be a material performance hit to have 100 - 250 rewrite rules in web.config as oppose to entries within routes.maproute that directly handles the mapping? Right?

Upvotes: 0

Views: 474

Answers (1)

NightOwl888
NightOwl888

Reputation: 56869

Either way, all of the rules will need to be executed before any of the actual routes are hit. So, the amount of performance that is used for either approach would be similar.

I suspect that the IIS rewrite module will be slightly faster because it happens before .NET even becomes involved in the request. However, the actual performance will depend on whether you use partial URL matches (fastest) vs case-sensitive complete URL matches (fast) vs case-insensitive complete URL matches (not-so-fast) vs using regular expressions (slow). Note that not all of these options are available in IIS rewrite.

Also, from a maintenance standpoint it makes much more sense to use IIS rewrite than mapping routes for obsolete URLs. Then you can keep these old URLs out of your application's configuration.

The only exception is if you want to handle the user edge cases where the browser doesn't respect an HTTP 301, and you want to make a user-friendly redirect page that ensures the user will know about the updated URL and update their bookmarks. The IIS rewrite module just sends a 301 response and assumes that the client will respect it (which isn't always the case).

Upvotes: 1

Related Questions