Go to DotNetFunda.com
 Online : 1145 |  Welcome, Guest!   Login
 
Home > Articles > ASP.NET > ASP.net redirection

Submit Article | Articles Home | Search Articles |

ASP.net redirection

red flag  Posted on: 7/23/2007 11:10:40 PM by Amitgupta007_99 | Views: 1237 | Category: ASP.NET | Level: Beginner


The easiest way to make a redirection in ASP.NET is using Response.Redirect(url).

What it actually does is, that it creates a response with the "302 (Object Moved)" status code and the target destination.

It tells the browser that the requested page is temporarily moved to a new location and then the browser makes a request to the new destination.

If the page is permanently moved, then the 302 status code is no longer correct.

Search engines also looks at 301 and 302 redirects differently. Here's a quote from The Internet Digest:

There is no natural way of doing a 301 redirect in ASP.NET, so you have to set the HTTP headers manually.

Below given is a small method that illustrates how to do it. All you have to do is to call it from the Page_Load or preferably from Page_Init or in ASP.NET 2.0 Page_PreInit.



protected void Page_PreInit(object sender, EventArgs e)

{

PermanentRedirect("http://www.newsite.com");

PermanentRedirect("/newfolder/");

}

private void PermanentRedirect(string url)

{

Response.Clear();

Response.StatusCode = 301;

Response.AppendHeader("location", url);

Response.End();

}

If you like this article, subscribe to our RSS Feed. You can also subscribe via email to our Interview Questions, Codes and Forums section.

Found interesting? Add this to:

| More



Please Sign In to vote for this post.

 
Latest post(s) from Amitgupta007_99

Latest Articles

About Amit Gupta

Experience:4 year(s)
Home page:http://www.r2ainformatics.com
Member since:Monday, July 23, 2007
Level:Starter
Status: [Member]
Biography:His experience covers a wide range of spectrum: SEO, Analytics, consultant, technical editor and college instructor . Amit holds more than 3 technical certifications and has completed MCA. Amit may be reached at amit@r2ainformatics.com

Submit Article

About Us | The Team | Advertise | Contact Us | Testimonials | Privacy Policy | Terms of Use | Link Exchange | Members | Go Top
General Notice: If you found plagiarised (copied) contents on this page, please let us know the original source along with your correct email id (to communicate) for further action.
Copyright © DotNetFunda.Com. All Rights Reserved. Copying or mimicking the site design and layout is prohibited. Logos, company names used here if any are only for reference purposes and they may be respective owner's right or trademarks. | 9/7/2010 12:36:25 AM