开发者

Which redirection is better - web.config or global.asax

I need to redirect some of the older pages in my application to new pages. I thought urlMapping in web.config is the efficient way to achieve this. But there is also another开发者_开发百科 way to redirect using global.asax. Which one is the efficient way for this. At what point in request execution does this asax and config file comes into the picture?


If I were mapping existing pages to new ones I would keep the old pages in place and flush a 301 permanent redirect to the client. This will preserve SEO, assuming this is a public site.

 Response.StatusCode = 301;
 Response.Status = "301 Moved Permanently";
 Response.RedirectLocation = location; // static, configuration, or database
 Response.End();

Overall I would go with rerouting instead of rewriting. Two great links for this are:

  • Chris Cavanagh - ASP.NET Routing… Goodbye URL rewriting?
  • Phil Haack - Using Routing With WebForms

For an overview of some different approaches prior to rerouting check out Scott Gu's Tip/Trick: Url Rewriting with ASP.NET


Use the URL Rewrite ISAPI filter to do the redirect - it is lower level and will run first, so you don't take a hit on the asp.net engine.

The page I linked also mentions ASP.NET Routing, the differences between them and how to choose between the two.


Here is one of way to write redirect by HttpHandler.

http://www.developerfusion.com/article/4643/implementing-http-handlers-in-aspnet/

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜