• Code
  • Tags
  • Users
  • Titles
  • Log in
  • Feedback
  • FAQ
Share Code
Welcome to ForkCan.com

ForkCan is all about sharing code in a social way.

Discuss, debate or argue with other devs about their or your own code.

Give other devs feedback or make a Fork (Make a better version of a shared code).

Rate the code, if you use the code mark it as used so others can see if the shared code is used by someone.

Help each other to be better devs and to be more productive.


Features not working yet:

Flag a post


QR Code

Tiny Url

http://4kcan.com/s/MTc3

Redirect Permanent from a non-www to a www using ASP.NET 4.0


0
950 0 0 0 0 2

protected void Application_BeginRequest(object sender, EventArgs e)
{
  if (Request.Url.Authority.StartsWith("www"))
      return;

  var url = string.Format("{0}://www.{1}{2}",
                   Request.Url.Scheme,
                   Request.Url.Authority,
                   Request.Url.PathAndQuery);

  Response.RedirectPermanent(url,true);
}

Share: twitter | facebook   Action: used | fork | flag

asp.net

Mark 'asp.net' tag as 'like'

Mark 'asp.net' tag as 'ignore'

redirect

Mark 'redirect' tag as 'like'

Mark 'redirect' tag as 'ignore'

url

Mark 'url' tag as 'like'

Mark 'url' tag as 'ignore'


 @fredrikn "I'm the master"
3.11k
July 12, 2010 5:41 PM
edited July 15, 2010 11:19 PM

Fork

 Redirect Permanent from a non-www to a www using ASP.NET 4.0 -  @fredrikn Monday 12, 2010 5:41 PM


0 Feedback


You must log in before you can give any feedback


2 Discussion(s)

Newest Oldest
0

Fredrik, you could probably helps us understand what's a permanent redirect (tip: http code and is it different from the old redirect we had in pre-v4.0 :P)

link | flag  | Reply

 @luisabreu
248
Monday 12, 2010 9:53 PM

0

HttpResponse.Redirect performs the redirection by returning a 302 HTTP status code (moved temporary) while ResponsePermanent returns a 301 HTTP status code (moved permanent) is a standard code in an HTTP response.

link | flag  | Reply

 @fredrikn "I'm the master"
3.11k
Monday 12, 2010 11:51 PM


You must log in before you can post a comment

Squeed
Made by: Fredrik Normén 2010