How to Use ASP to Force SSL for Specific Pages
ID: Q239875
|
The information in this article applies to:
-
Microsoft Internet Information Server 4.0
-
Microsoft Internet Information Services version 5.0
SUMMARY
It is often good security practice to require Secure Sockets Layer (SSL) for certain pages on a Web site. Although this can be configured through the Internet Services Manager (ISM) in the Microsoft Management Console (MMC), you can also use Active Server Pages (ASP) to force SSL for specific pages without making changes in the MMC.
MORE INFORMATION
Note: This article assumes the following conditions:
- IIS is running on standard ports:
HTTP = Port 80
HTTPS = Port 443
- IIS has a valid SSL certificate installed.
- The Web site or virtual server being used does not use HTTP/1.1 Host Headers for name resolution.
To force SSL using ASP, perform the following steps:
- Save the following code in the root of your Web server as an include file named ForceSSL.inc:
<%
If Request.ServerVariables("SERVER_PORT")=80 Then
Dim strSecureURL
strSecureURL = "https://"
strSecureURL = strSecureURL & Request.ServerVariables("SERVER_NAME")
strSecureURL = strSecureURL & Request.ServerVariables("URL")
Response.Redirect strSecureURL
End If
%>
- For each page that requires SSL, insert the following code at the top of the page to reference the include file from the previous step:
<%@Language="VBSCRIPT"%>
<!--#include virtual="/ForceSSL.inc"-->
- When each page is browsed, the ASP code contained in the include file will detect the port to determine if HTTP is being used. If HTTP is being used, the browser will be redirected to the same page using HTTPS.
For more information on this topic, please see the following articles in the Microsoft Knowledge Base:
Q171084 How to Install a Certificate
Q172023 Secure Sockets Layer (SSL) Options
Q187504 HTTP 1.1 Host Headers Not Supported When Using SSL
Q228991 How to Create and Install an SSL Certificate in IIS 4.0
Q228836 Installing a New Certificate for Use in SSL/TLS
Additional query words:
Keywords :
Version : winnt:4.0,5.0
Platform : winnt
Issue type : kbhowto