Recently I migrated an ASP.net site to ASP.net MVC site. Earlier there were two host headers one mydomain.com and another is www.mydomain.com. My SEO says you should use only on
You could use config or Url Rewriter in IIS, but the best method I've found is just to put some code in Application_BeginRequest()
in your global.asax.cs
like this:
var HOST = "www.mydomain.com";
if ( !Request.ServerVariables[ "HTTP_HOST" ].Equals(
HOST,
StringComparison.InvariantCultureIgnoreCase )
)
{
Response.RedirectPermanent(
( HttpContext.Current.Request.IsSecureConnection ? "https://" : "http://" )
+ HOST
+ HttpContext.Current.Request.RawUrl );
}
Because you're doing this in code, you can have whatever logic you need on a per-request basis.