Gunnar Peipman's ASP.NET blog

ASP.NET, C#, SharePoint, SQL Server and general software development topics.

Sponsors

News

 
 
 
DZone MVB

Links

Social

ASP.NET 4.0 SEO features: Response.RedirectPermanent()

ASP.NET 4.0 introduces some SEO improvements. Response has now new method called RedirectPermanent(). This method performs same redirect as Response.Redirect() but it uses response code 301. You can find more information about HTTP response codes from HTTP 1.1 specification, chapter 10. Status Code Definitions.

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.

To illustrate difference between Response.Redirect() and Response.RedirectPermanent() let’s look at simple example. We need one usual ASP.NET Web Application with Global.asax file. In Global.asax file we have to implement BeginRequest() method.

C#
protected void Application_BeginRequest(object sender, EventArgs e)
{
    if (Request.FilePath == "/our-products.aspx")
    {
        Response.Redirect("/products.aspx", true);
    }
    if (Request.FilePath == "/about-us.aspx")
    {
        Response.RedirectPermanent("/about.aspx", true);
    }
}

VB.NET


Protected Sub Application_BeginRequest(ByVal sender As Object, _
   
ByVal e As EventArgs)
   
    If Request.FilePath = "/our-products.aspx" Then
        Response.Redirect("/products.aspx", True)
    End If
    If Request.FilePath = "/about-us.aspx" Then
        Response.RedirectPermanent("/about.aspx", True)
    End If
End Sub

Now let’s run our web application and make the following requests:

  • /our-products.aspx
  • /about-us.aspx

In both cases we will be redirected but redirections are different. Here is my little mix of FireBug outputs for these requests and I think it is very self describing.

Response.RedirectPermanent() has also overload with one parameter, just like Response.Redirect() does. If you have pages that exist in search engines but are moved to other location in your application then Response.RedirectPermanent() helps you build redirection controlling mechanism that likes to search engine spiders.


kick it on DotNetKicks.com vote it on Web Development Community pimp it Progg it Shout it
Posted: May 27 2009, 02:29 AM by DigiMortal | with 31 comment(s)
Filed under: ,

Comments

DotNetShoutout said:

Thank you for submitting this cool story - Trackback from DotNetShoutout

# May 26, 2009 7:33 PM

DotNetBurner - ASP.net said:

DotNetBurner - burning hot .net content

# May 26, 2009 7:34 PM

PimpThisBlog.com said:

Thank you for submitting this cool story - Trackback from PimpThisBlog.com

# May 26, 2009 7:36 PM

DotNetKicks.com said:

You've been kicked (a good thing) - Trackback from DotNetKicks.com

# May 26, 2009 7:37 PM

Gunnar Peipman's ASP.NET blog said:

Here are my postings about Visual Studio 2010 and .Net Framework 4.0 that may be interesting to my readers

# May 26, 2009 7:42 PM

Seo Swap | | ASP.NET 4.0 SEO features: Response.RedirectPermanent() - Gunnar … » Seo Swap | said:

Pingback from  Seo Swap | | ASP.NET 4.0 SEO features: Response.RedirectPermanent() - Gunnar … » Seo Swap |

# May 27, 2009 4:26 AM

ASP.NET 4.0 SEO features: Response.RedirectPermanent() - Gunnar … said:

Pingback from  ASP.NET 4.0 SEO features: Response.RedirectPermanent() - Gunnar …

# May 27, 2009 4:32 AM

ASP.NET 4.0 SEO features: Response.RedirectPermanent() - Gunnar … : Search Engine Optimization Blog - NewSunSEO - New York said:

Pingback from  ASP.NET 4.0 SEO features: Response.RedirectPermanent() - Gunnar …  : Search Engine Optimization Blog - NewSunSEO - New York

# May 27, 2009 5:46 AM

Web Development Community said:

You are voted (great) - Trackback from Web Development Community

# May 27, 2009 5:54 AM

ASP.NET 4.0 SEO features: Response.RedirectPermanent() - Gunnar … « blog.xkid.ro said:

Pingback from  ASP.NET 4.0 SEO features: Response.RedirectPermanent() - Gunnar … «  blog.xkid.ro

# May 27, 2009 6:13 AM

ASP.NET 4.0 SEO features: Response.RedirectPermanent() - Gunnar … | SEO News & Views said:

Pingback from  ASP.NET 4.0 SEO features: Response.RedirectPermanent() - Gunnar … | SEO News & Views

# May 27, 2009 7:01 AM

ASP.NET 4.0 SEO features: Response.RedirectPermanent() - Gunnar … | Superstructure said:

Pingback from  ASP.NET 4.0 SEO features: Response.RedirectPermanent() - Gunnar … | Superstructure

# May 27, 2009 8:36 AM

ASP.NET 4.0 SEO features: Response.RedirectPermanent() - Gunnar … « blog.xkid.ro said:

Pingback from  ASP.NET 4.0 SEO features: Response.RedirectPermanent() - Gunnar … «  blog.xkid.ro

# May 27, 2009 10:58 AM

ASP.NET 4.0 SEO features: Response.RedirectPermanent() - Gunnar … :: UltraBlog said:

Pingback from  ASP.NET 4.0 SEO features: Response.RedirectPermanent() - Gunnar … :: UltraBlog

# May 27, 2009 6:30 PM

Joe Hendricks, SoftwareRunners said:

Thank you Gunnar for your excellent previews of Asp.Net 4 !

- Joe

# May 29, 2009 5:08 PM

progg.ru said:

Thank you for submitting this cool story - Trackback from progg.ru

# July 4, 2009 4:07 AM

bespoke_web_developer said:

also:

       Response.Clear();

       Response.Status = "301 Moved Permanently";

       Response.RedirectLocation = PathOrUrl;

       Response.End();  

# May 8, 2010 12:33 PM

Fanindra said:

Response.RedirectPermanent() is server side mechanism then how it's work for SEO ?

# July 26, 2010 5:49 AM

DigiMortal said:

Because it sends out response to client. Not every HTTP request ends up with response that is shown to user as page. 301 and 302, by example, return header called Location that contains URL  of page where client should go instead.

302 is temporary redirect and that means that resource may be soon available in current address again. So, client has to check it always when the request is made. 301 is permanent redirect that tells client that resource is moved to another address and it will not be available on current address ever again.

One of those clients is your browser and the other one is search engine spider. The last one doesn't like those 302 responses and that's why RedirectPermanent is important.

# July 26, 2010 11:17 AM

website design melbourne said:

thanks for informing me. Can we make database programmes in mysql without making dsn..?

# January 18, 2011 5:43 AM

Weekly Links– 2010_04 | MS-Joe (Joe Stagner) said:

Pingback from  Weekly Links– 2010_04 | MS-Joe (Joe Stagner)

# January 28, 2011 9:44 AM

Amit said:

Thanks to expose nice feature of .net 4.0.

# May 5, 2011 7:33 AM

Affordable SEO Services said:

Best Blog on ASP.NET 4.0 SEO features, Thanks for sharing.....

# June 9, 2011 9:45 AM

yasir115 said:

nice information but i have one question can one told me what happen if we used redirectpermanently.

will it effect on search engine pages that it index ?

what happen if we redirect paramently that page that Google index ? Page index remain or removed from the google.

any told me ?

thanks in advance

yasir butt

# July 4, 2011 6:42 AM

» Simple 301 Redirects ASP.NET 4.0 in Code Alan Feekery said:

Pingback from  » Simple 301 Redirects ASP.NET 4.0 in Code Alan Feekery

# September 20, 2011 8:13 AM

» Simple 301 Redirects ASP.NET 4.0 in Code Alan Feekery said:

Pingback from  » Simple 301 Redirects ASP.NET 4.0 in Code Alan Feekery

# September 20, 2011 8:13 AM

Brij Sharma said:

It is good that we have this option available to redirect.

I was looking to redirect all "non www" urls to "www urls". Can we do this at the server level(IIS 7 available available through websitepanel) itself or this is the only way available?

# September 23, 2011 3:58 PM

india domain registration said:

This is a really good read for me. Must admit that you are one of the best bloggers I have ever read. Thanks for posting this informative article.love it.

# January 4, 2012 12:22 AM

planoimmope said:

Hello! Just want to say thank you for this interesting article! =) Peace, Joy.

# January 22, 2012 5:33 PM

Top Technical Roadblocks Keeping Your Website from Being Seen by Searchers: Webinar Resources « My SEO Expert said:

Pingback from  Top Technical Roadblocks Keeping Your Website from Being Seen by Searchers: Webinar Resources « My SEO Expert

# June 29, 2012 5:07 PM

Simple 301 Redirects ASP.NET 4.0 in Code « alanfeekery.com said:

Pingback from  Simple 301 Redirects ASP.NET 4.0 in Code « alanfeekery.com

# August 13, 2012 5:59 AM