detecting SSL or not

  • Thread starter Thread starter Brian Henry
  • Start date Start date
B

Brian Henry

Hi,

I have a web site i want to be SSL (we already have the cert and everything
from verisign) but i want port 80 to redirect to the ssl connection 443
(HTTPS) so if they go to the site at http://site it will determin hey im not
ssl and redirct to https://site how would you do this? thanks
 
Hi,

I have a web site i want to be SSL (we already have the cert and everything
from verisign) but i want port 80 to redirect to the ssl connection 443
(HTTPS) so if they go to the site at http://site it will determin hey im not
ssl and redirct to https://site how would you do this? thanks

you have to detect SSL, and then construct the https://... url yourself
(no automated way I know of to do that OOTB, someone may have written a
utility class to do this somewhere). The easiest way to detect is to
check if Request.Url.Scheme is equal to System.Uri.UriSchemeHttps or
System.Uri.UriSchemeHttp. Then build the new https URL yourself (if
needed).

Here's a posting that answered this, also has an example of switching to
SSL in old ASP:
http://www.dotnet247.com/247reference/msgs/31/156879.aspx
 
The "HTTPS" key within the Server object should tell you whether SSL is
being used or not. If this doesn't work for you, then use the "SERVER_PORT"
or "SERVER_PORT_SECURE" keys within the Server object.
 
thanks

ASP.Confused said:
The "HTTPS" key within the Server object should tell you whether SSL is
being used or not. If this doesn't work for you, then use the "SERVER_PORT"
or "SERVER_PORT_SECURE" keys within the Server object.
 
Thanks for all the suggestions.

Hi Brian,

Here are some other tech articles in codeproject discussing the redirecting
from http to https processing in asp.net, the author has built a custom
module to perform this function:

#Switching Between HTTP and HTTPS Automatically
http://www.codeproject.com/aspnet/WebPageSecurity.asp

#Switching Between HTTP and HTTPS Automatically: Version 2
http://www.codeproject.com/useritems/WebPageSecurity_v2.asp

Hope also helps. Thanks.

Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Get Preview at ASP.NET whidbey
http://msdn.microsoft.com/asp.net/whidbey/default.aspx
 
Here's a user control that I made that works quite well. All you have to
do is include it in the pages that you want to ensure SSL with...
<%@ Control language="c#" %>
<script runat="server">
public void Page_Load(object sender, System.EventArgs e)
{
if (!Request.IsSecureConnection)
{
string strSecureURL = "https://";
strSecureURL += Request.ServerVariables["SERVER_NAME"];
// strSecureURL += Request.ServerVariables["URL"];
strSecureURL += Request.RawUrl;
Response.Redirect(strSecureURL);
}
}
</script>

Shan Plourde
 
Back
Top