I am looking for the "best practice" way of secure site redirection with IIS7 and ASP.net. Say I have two domain names:
- mydomain.com
- mydomain.net
each with a www subdomain.
I have a single EV certificate that uses the common name:
- www.mydomain.com
Therefore, the user can access the site 8 different possible ways:
- http://mydomain.com
- http://mydomain.net
- http://www.mydomain.com
- http://www.mydomain.net
- and also using https://
In order for the user to not receive certificate errors, he/she must be directed to
- https://www.mydomain.com
What is the best way to make this work transparently to the user while still ensuring that IIS serves up only secure content? In the past I have used web.config to redirect to a sub page like this:
<system.webServer>
<httpRedirect destination="https://www.mydomain.com/secureSubPage" />
or with wildcard certificates using this block in a common base page:
if (!Request.IsSecureConnection)
{
Response.Redirect(Request.Url.ToString().Replace("http:", "https:"), true);
return;
}
if (!Request.Url.ToString().Contains(".com"))
{
Response.Redirect(Request.Url.ToString().Replace(".net", ".com"), true);
return;
}