top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

What is RedirectPermanent in ASP.Net 4.0?

0 votes
351 views
What is RedirectPermanent in ASP.Net 4.0?
posted May 12, 2017 by Jdk

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

1 Answer

0 votes

Full domain redirects like the one you mention are best done at the IIS level, but if you aren't able to configure IIS you could use Response.RedirectPermanent, which is new in ASP.NET 4.0. This will redirect with a 301 (permanent) status code instead of the 302 (object moved) status code used by a standard Response.Redirect.

Put this code inside Global.asax file:

protected void Application_BeginRequest(object sender, EventArgs e)
{
    if (!(Request.Url.AbsoluteUri.ToLower().Contains("www")))
    {
      Response.RedirectPermanent(Request.Url.AbsoluteUri.Replace("http://", "http://www."));
    }
} 
answer May 12, 2017 by Shweta Singh
Similar Questions
+7 votes

How to create your own controls?
Basic steps will be helpful.

+4 votes

How to Generic Method to Create and Execute Parameterized SQL Query in .NET 4.0 ?

+2 votes

How to use Zip operator in Linq with .NET 4.0?

...