views:

315

answers:

2

Ok due to some client security something or other the DB tracking only works when there is a www in front of the subdomain. I want to prevent further support tickets from users going to thewebsite.com and finding out later the DB was not recording for them. I need it to redirect to www.thewebsite.com if they hit thewebsite.com.

PS: I heard people rant about the www should be deprecated thing already so save your breath please ;)

+4  A: 

If you pass both www. and non www. requests to ASP.NET you can check the Request.Url object and check if it has www if not you can Response.Redirect to the www. option.

Personally I would go into IIS rather, create a separate website which only accepts non www. requests and use the redirect options on the home tab to redirect it to the www. URL. This means no code changes are needed and any applications which handle 503 status messages will update the URL automatically.

Robert MacLean
care to elaborate? how do i allow/disallow www for a site in IIS?
shogun
Personally I would configure the site to accept the host headers for both www.foo.com and foo.com - no second site - @ryan you can do this through site properites > web site > advanced... (next to the IP address field)
annakata
+2  A: 

Use a HttpModule to check for the url; this would help you avoid testing for that condition in every page or the base page (if you have any). Also, if you redirect make sure that you are not using Response.Redirect as it issues a non-permanent redirect (302) instead of a permanent redirect (301) for SEO reasons.

Response to PS: Actually www prefix is always better instead of the root url as it allows you to have cookie-less domains for static content thus reducing the amount of data sent back and forth between the browser and the server.

Sachin
Nice reason for using www.
Sam Hasler