I put the following code in the Global.asax file:
protected void Application_BeginRequest(Object sender, EventArgs e)
{
if (Request.Url.Port != 443)
{
Response.Redirect ("https://www.yourdomain.com" + Request.Url.AbsolutePath, true);
}
}
This uses
Request.IsSecureConnection
to determine if the call was made over SSL.
So
if (Request.IsSecureConnection)
{
Response.Write("HTTPS");
}
else
{
Response.Write("HTTP");
}
Another way to write this:
if (!Request.IsSecureConnection)
{
string serverName =HttpUtility.UrlEncode(Request.ServerVariables["SERVER_NAME"]);
string filePath = Request.FilePath;
Response.Redirect("https://" + serverName + filePath);
}
No comments:
Post a Comment