1

We have a legacy ASP.NET website in which complex redirect rules are coded in Global.asax. Actually this logic processes requests with several optional or variable parts like

{http|https}://[www.]ourdomain.com/[Home/]Products/old-product-name/page.aspx

and redirects them to

https://ourdomain.com/new-product-name/

Theoretically this logic can be rewritten with a set of rules for the IIS URL rewrite module. I am considering this approach for two reasons. First, this should simplify the redirect logic as it will be written as a set of declarative rules. Second, we need to add more and more redirect rules, and it will be simpler to do this in the format of the URL Rewrite rules.

The question: does it make sense to rewrite our redirect logic with the URL Rewrite module? Can it lead to performance degrade and the like? Or maybe, the best way to do what we need is to use Global.asax together with the URL Rewrite rules, coding complex rules in Global.asax and using URL Rewrite for simple redirects?

0

As long as your rules can be expressed as regular expressions for the paths, combined with conditions related to headers, server variables, etc. they can be rewritten as URL Rewrite rules. Obviously you can't have any specific application data linked to the rules (those should be included in your app, probably in the global.asax file or in an HTTPModule.

You'll get better performance, they will be independent of the application code or technology, will be easier to maintain and you'll have extra features such as internal rewrites of the requests instead of redirections (for example to expose friendly URLs but use "ugly" ones internally), redirection maps that you can manage separately, and many more.

  • Global.asax is a compiled thing, so I thought putting all rules into the URL Rewrite module may lead to worse performance as the module processor possibly interprets them every time. – TecMan Aug 7 at 9:28
  • 1
    URL Rewrite uses compiled regular expressions and caching apart from taking advantage of Kernel mode caching to make sure it's imperceptible even in webs with millions of unique users per month and thousands of rules (i have first hand experience with this). You shouldn't notice any difference using it. The only costly ones are the outbound rules, depending on how you use them and what you do. I've tried to find a good reference about this online and only got here: blogs.iis.net/danielvl/url-rewrite-2-0-performance – jalarcon Aug 7 at 13:08
  • So URL Rewrite rules can even work faster due to smart caching, right? – TecMan Aug 7 at 14:19
  • URL Rewrite always works the best it can, taking into account a lot of things explained in my previously mentioned link and other articles that are pointed out in that link. But, in general, it will work better and faster than writing your own rules in your app, and you get a lot of advantages that will outweigh the custom code even if it were slightly faster (which is not the case). – jalarcon Aug 8 at 7:22
  • I faced the 301 redirect chain problem when I tried to implement what I need in URW Rewrite rules. See my question here. – TecMan Aug 8 at 7:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.