Go to DotNetFunda.com
 Welcome, Guest!  
LoginLogin  
Expose your profile for FREE in Xpose
Submit: Article | Interview Question | Code | Question | Xpose | Joke | Link || Search  
 Skip Navigation Links Home > Articles > ASP.net redirection

All Articles | Post Articles |  Subscribe to RSS

ASP.net redirection

 Posted on: 7/23/2007 11:10:40 PM by Amitgupta007_99 | Views: 608 | Category: ASP.NET | Level: Beginner | Print Article
ASP.NET 3.5 Hosting and MS SQL 2008!
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.

Advertisement

Showcase
Are you an employee, employer or a service provider? Showcase your profile in Xpose section to get better opportunity.

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();

}

Interesting?  Bookmark and Share kick it on DotNetKicks.com


About Amit Gupta

Experience:4 year(s)
Home page:http://www.r2ainformatics.com
Member since:Monday, July 23, 2007
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
 Latest post(s) from Amitgupta007_99

   ◘ Robots.txt and Search Engine Spiders - SEO posted on 11/26/2007 10:53:03 AM
   ◘ Search Engine Optimization posted on 11/23/2007 6:09:14 AM
   ◘ Web Analytics posted on 10/19/2007 11:54:48 AM
   ◘ ASP.net redirection posted on 7/23/2007 11:10:40 PM




About Us | Contact Us | Privacy Policy | Terms of Use | Link Exchange | Members | Go Top
All rights reserved to DotNetFunda.Com. Logos, company names used here if any are only for reference purposes and they may be respective owner's right or trademarks.
(Best viewed in IE 6.0+ or Firefox 2.0+ at 1024 * 768 or higher)