I need to redirect user to a secure connection with www included in url my code is working for https connection but if user types https mysite.com. it should always redirect user to https www.mysite.com below is my code
if (HttpContext.Current.Request.IsSecureConnection.Equals(false) && HttpContext.Current.Request.IsLocal.Equals(false))
{
Response.AddHeader("Strict-Transport-Security", "max-age=31536000");
Response.Status = "301 Moved Permanently";
Response.RedirectPermanent("https www.mysite.com" + HttpContext.Current.Request.RawUrl);
}
if (Request.Url.Host.ToString().StartsWith("www", StringComparison.OrdinalIgnoreCase).Equals(false))
{
Response.AddHeader("Strict-Transport-Security", "max-age=31536000");
Response.Status = "301 Moved Permanently";
Response.RedirectPermanent("https www.mysite.com" + HttpContext.Current.Request.RawUrl);
}