detecting SSL or not

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
 
C

Craig Deelsnyder

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
 
A

ASP.Confused

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.
 
B

Brian Henry

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.
 
S

Steven Cheng[MSFT]

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
 
S

Shan Plourde

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
 
Joined
May 26, 2007
Messages
2
Reaction score
0
Simplified code

The above code won't preserve querystring variables. Use this simplification instead:


Private Sub SecureOrRedirect()
If Not (Request.IsSecureConnection) Then
Dim strSecureURL As String = "https://"
strSecureURL = Request.Url.AbsoluteUri.ToLower.Replace("http://", "https://")
End If
End Sub​


Then in Page Load call the function:

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
SecureOrRedirect()​

David Rodecker
Getting Local Businesses Online
 
Last edited:

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,065
Latest member
OrderGreenAcreCBD

Latest Threads

Top