What is RedirectPermanent in ASP.Net?

RedirectPermanent Performs a permanent redirection from the requested URL to the specified URL. Once the redirection is done, it also returns 301 Moved Permanently responses.

In ASP.NET, RedirectPermanent is a method used to perform a permanent redirection of a request to a different URL. When a client (typically a web browser) makes a request to a specific URL, the server responds with an HTTP 301 status code along with the new URL. This informs the client that the requested resource has been permanently moved to a different location, and subsequent requests should be directed to the new URL.

Here’s an example of how RedirectPermanent can be used in ASP.NET:

csharp
public ActionResult OldUrl()
{
// Redirect to the new URL permanently
return RedirectPermanent("/new-url");
}

In this example, when a request is made to the OldUrl action method, it redirects the client to the /new-url URL with a permanent redirection status.

It’s worth noting that using RedirectPermanent is beneficial for search engine optimization (SEO) purposes, as search engines typically transfer the ranking of the old URL to the new one when they encounter a permanent redirection (HTTP 301).