Response.Redirect() vs Response.RedirectPermanent()
Asked Answered
E

1

6

I am new to ASP.Net 4.0, and have seen a new feature called Response.RedirectPermanent(). I have checked a few articles, but I'm unable to understand clearly the actual meaning and difference of Response.RedirectPermanent() over Response.Redirect().

According to Gunnar Peipman,

Response.Redirect() returns 302 to browser meaning that asked resource is temporarily moved to other location. Permanent redirect means that browser gets 301 as response from server. In this case browser doesn’t ask the same resource from old URL anymore – it uses URL given by Location header.

Why do I need to check the server response such as 301, 302? And how does it get permanently redirected the page to the server?

Egress answered 14/5, 2013 at 8:3 Comment(0)
J
12

301 response (RedirectPermanent) is very useful for SEO purposes. For example, you had a site implemented in ASP.NET WebForms and redesigned using ASP.NET MVC. You'd like to inform search engines that page /Catalog/ProductName.aspx becomes /products/product-name. Then you set 301 redirect from /Catalog/ProductName.aspx to /products/product-name and links in search engines' indices will be replaced. 302 (Redirect) is mostly for internal purposes. For example, the redirect after login (if returnUrl was set in URL).

Jenny answered 14/5, 2013 at 8:11 Comment(2)
Which one is better to use?Qualm
Depends on situation. Redirect 301 is better to use for SEO purposes. When you need to tell to search engine that some page is moved to another location. Redirect 302 is better for application flow. For example, login page might redirect back to the page it was launched from.Jenny

© 2022 - 2024 — McMap. All rights reserved.