Showing posts with label SEO. Show all posts
Showing posts with label SEO. Show all posts

Difference between Response.Redirect, Response.RedirectParmanent and Servier.Transfer


According to MSDN

Response.Redirect(): Redirects a request to a new URL

Response.RedirectParmanent(): Performs a permanent redirection from a requested URL to a specified URL.

Server.Transfer(): Sends all of the information that has been assembled for processing by one .asp file to a second .asp file.

Response.RedirectParmanent() is an extension function introduced in .NET 4.0.The reason behind introducing this method is to indicate the Response Code to the Search Engine that the page is permanently moved.The Response.Redirect generates Response code as 302 whereas RedirectParmanent returns 301.

Thus say you have a page, and which is included to search engine for a long time, if you use Response.Redirect() it will not change this effect to the search engine(taking this a temporary change), while if you use Response.RedirectParmanent() it will take it as permanent.

In case of Server.Transfer() the actual response is updated, but there is no effect to the search engine, and search engine will think the output is coming from the same page that is called.

For example, if you have 2 pages (Default.aspx and Home.aspx) where Default.aspx redirects to Home.aspx, the above 3 methods shows the following behavior.

1. Response.Redirect() : Search Engine will take this redirection as Temporary(Status 301) and always keep Default.aspx in its cache.

2. Response.RedirectParmanent() : Search Engine will take this a permanent redirection(Status 302) and will remove Default.aspx from its database and include Home.aspx for better performance on search.

3. Server.Transfer() : Search Engine will be unaware of any redirection been took place (Status 200) and will keep Default.aspx to its database. It will think Default.aspx is producing the output response of Home.aspx.

When to use:


  • Response.Redirect() is perfect when your page is temporarily changed and will again be reverted to original within a short span of time.
  • Response.RedirectParmanent() when you are thinking of deleting the original page totally after the search engines changes its database.
  • Server.Transfer() when you are thinking of keeping the page for ever, and to let search engine unaware of this redirection. 

SEO: Adding Meta Tags to ASPX Page Programmatically

Adding page-specific meta tags, like "Description" and "Keywords" is very important in SEO optimization. Meta tags could be added directly to the head section of the web pages, such as .html or plain .aspx,but it is less than trivial in case of .aspx page referring masterpage because the head section is included in master page, so by default all pages referring to it will share the same set of meta tags.

"HtmlMeta" is a class available in "System.Web.UI.HtmlControls" namespace, which allows to add page-specific meta tags to the .aspx pages referring the same masterpage from code behind.Following is the example for how to use this class This code snippet should be included in Page_Load event of.aspx page.


HtmlHead head = (HtmlHead)Page.Header;

HtmlMeta oMeta1 = new HtmlMeta();
oMeta1.Name = "Description";
oMeta1.Content = "this is the Page description";
head.Controls.Add(oMeta1);

HtmlMeta oMeta2 = new HtmlMeta();
oMeta2.Name = "Keywords";
oMeta2.Content = "Keyword1,Keyword2....";
head.Controls.Add(oMeta2);

For example if one page deals with .NET Articals, and another page deals with Java artical and both sharing the same master page, then code snippets are like below.


For .NET Articles Page

HtmlHead head = (HtmlHead)Page.Header;

HtmlMeta oMeta1 = new  HtmlMeta();
oMeta1.Name = "Description";
oMeta1.Content = "this is the .NET Page description";
head.Controls.Add(oMeta1);

HtmlMeta oMeta2 = new  HtmlMeta();
oMeta2.Name = "Keywords";
oMeta2.Content = "C#.NET,ASP.NET,Ajax,VB.NET,OOPs,Microsoft";
head.Controls.Add(oMeta2);

For Java Articles Page

HtmlHead head = (HtmlHead)Page.Header;

HtmlMeta oMeta1 = new  HtmlMeta();
oMeta1.Name = "Description";
oMeta1.Content = "this is the Java Page description";
head.Controls.Add(oMeta1);

HtmlMeta oMeta2 = new  HtmlMeta();
oMeta2.Name = "Keywords";
oMeta2.Content = "Java,Oracle,Sun,OOPs,J2EE";
head.Controls.Add(oMeta2);