-->

When to use routes vs. rewrite rules?

2019-07-15 04:11发布

问题:

I'm trying to debug a problem with routing and I've just realized that MVC routes do something extremely similar to url rewriting but I don't have a good understanding of which situations call for routing and which call for url rewriting. Can someone please explain where these two technologies differ and for which situations each is appropriate?

回答1:

Url Rewriting analyzes the requested URL and changes it to a different URL on the same server. The URL rewriting module runs early in the request-processing pipeline, modifying the requested URL before the Web server decides which handler to use to process the request.

Routing is a request-dispatching mechanism that occurs after Url Rewriting. When a request is made to a Web server ASP.NET routing looks up the requested URL path in the list of registered routes. If the route is found, the corresponding handler for that route is invoked to process that request.

Use routes when you are developing a new application or maintaining an existing one. Use Url rewriting when you want to patch a legacy application without changing it internally.

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