OVERVIEWRecently, I came to know about the new function of Response named as Response.RedirectPermanent. So what is Response.RedirectPermanent? Where to use it?
Its same like Response.Redirect() function as it redirects you from one page to another but it returns HTTP status code 301 as compared to HTTP 302 returned by response.redirect().
So, in this article we would have brief overview of Response.RedirectPermanent.
Response.RedirectPermanentConsider a following scenario:
We have a web application which sells products to end users. In order to increase the user count or to bring more users to the website, company decides to start with discounts on certain products. Hence, it introduces the new page named as Discount.aspx listing all the products which has discounts on them. When user clicks on any of the discounted products, website redirects the user to page named as Products.aspx where user can view the details of product.
In order to increase the revenue company hires the SEO and registers the page on different search engines like Google, Yahoo etc. Hence, discount page gets registered on different search engines.
Now, after some months company decides that it don't want to give discounts on the products and thinks of removing the page. But they don't want to lose their customers who were coming to their site through discounted page.
In this case, we have two options
1) Copying the content of products page to discounted page
Disadvantage: When search engines see the same data on both discounted and products page, they can penalize the site for having the duplicate content and would delist the site.
2) Use Response.Redirect
We can use Response.Redirect on the page load of discounted page which would redirect the user to products page.
Disadvantage: When we use response.redirect, then it returns the status code as HTTP 302 temporarily redirected to different search engines.So, search engine store this information in their table that this discounted page had returned status code HTTP 302 and it was temporary re-directed.
Search engines expect that next time when we would hit discounted page, it would show the data and shouldn't return 302 status code. If next time again, page returns status code 302 then search engine penalizes the site and would delist the site.
Hence, in this scenario we should always use Response.RedirectPermanent.
What does Response.RedirectPermanent?
When we use Response.RedirectPermanent then it returns status code HTTP 301 Moved Permanently.It tells different search engines this page has permanently moved to new page. By this different search engines updates their index with new page. So, next time if someone clicks on discounted page, user would be automatically directed to products page by search engines.
So, let's build a small application, which would have two buttons - one button would use Response.Redirect and other button would use Response.RedirectPermanent.
We can view the GET request details by using the tool named as HTTPDebugger.Below are the GET request. You can see that when we have use Response.Redirect then browser has returned status code as 302 Found; however in case of Response.RedirectPermanent status code returned is 301 Moved Permanently.
Below is the screenshot
ConclusionWhenever we want to remove any page from website, we should always use Response.RedirectPermanent. With this we wouldn't loose our customers directed to our site through different search engines.
Hope with this article, we would have brief overview of Response.RedirectPermanent.