Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ASP.NET - redirect 301

How do I redirect permanently in ASP DOT NET? I'd like to do a 301 redirect from one page on my site to another page.

like image 410
Arjun Avatar asked Mar 07 '09 01:03

Arjun


People also ask

What is 301 redirect asp net?

301 is an HTTP status code sent by a web server to a browser. A 301 signals a permanent redirect from one URL to another, meaning all users that request an old URL will be automatically sent to a new URL.

How do I redirect a 301 URL?

Permanently redirect old pages or entire folders of pages to new locations in your Webflow site using the 301 Redirects settings: Open Project settings > Hosting > 301 redirects‍ Add the old URL in the “Old Path” field (eg. /old-url) Add the new URL in the “Redirect to Page” field (/entirely/new-url/structure)

Which is better 301 or 302 redirect?

For permanent changes to a website and continued ranking through SEO, a 301 redirect is necessary. On the other hand, if you're only performing a temporary change, a 302 redirect is better. It tells the search engine that the changes are temporary and may not impact the original page's SEO ranking.


1 Answers

protected void Page_PreInit(object sender, EventArgs e)
{
    Response.StatusCode = 301;
    Response.StatusDescription = "Moved Permanently";
    Response.RedirectLocation = "AnotherPage.aspx";
    HttpContext.Current.ApplicationInstance.CompleteRequest();
}

And in 4.0, there's a simple HttpResponse.RedirectPermanent() method that does everything above for you:

Response.RedirectPermanent("AnotherPage.aspx");
like image 144
Chris Fulstow Avatar answered Oct 15 '22 17:10

Chris Fulstow