Wednesday, August 17, 2005

 

Redirect Browser to HTTPS

By adding the following code to your Global.asax, you can determine if a user's browser is accessing your site using SSL and if not, automatically redirect their browser to the same URL with an HTTPS prefix.

protected void Application_BeginRequest(Object sender, EventArgs e)
{
if (Request.ServerVariables["HTTPS"] == "off")
{
string redir = "https://" + Request.ServerVariables["SERVER_NAME"] +
Request.ServerVariables["SCRIPT_NAME"];
if (Request.ServerVariables["QUERY_STRING"] != "")
redir += "?" + Request.ServerVariables["QUERY_STRING"];

Response.Redirect(redir);
}
}

Comments:
hi,
thanks for this; can you give the complete content of the global.asax file including the header tags and such?
email code AT davidcobb.net if you would be so kind.
THANK YOU! :)
-david
 
Post a Comment

Links to this post:

Create a Link



<< Home
Content copyright ©2003-2006 Tod Birdsall