There was a problem loading the comments.

Forcing www in the website

Support Portal  »  Knowledgebase  »  Viewing Article

If you want users to always use to connect to your website (rather than just, you can add the following code to your global.asax:
protected void Application_BeginRequest( object sender, EventArgs e){
   //check the request to make it starts with www
   //and is not localhost (dev)
   if (!Request.Url.Host.StartsWith( "www" ) && !Request.Url.IsLoopback)
  //no ... redirect.
UriBuilder builder = new UriBuilder (Request.Url);
      builder.Host =
"www." + Request.Url.Host;
true );
} This code will run at the beginning of every request, check the URL being used, and redirect to So that you can even use this on your local machine for testing, it also checks to see if it's localhost. 

Share via
Did you find this article useful?  

Related Articles

© Softsys Hosting