Force a Secure Connection (SSL) Using ASP.NET (MVC 3) in Cloud Sites
Using ASP.NET, you can run code to force SSL on a single page on your site. This article contains sample code for this procedure.
Note: |
| The code provided below is only an example. Your specific website may require different code. As outlined in our Terms of Service and Cloud Sites Spheres of Support Expectations, we are unable to help you troubleshoot code issues. We recommend speaking with your developer before implementing any scripts. |
Using ASP.NET, you can run similar code to force SSL on a single page on your site. An example is below.
<%@ Page Language="C#" %>
<! DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<!script runat="server">// <!
protected void Page_Load(object sender, System.EventArgs e)
{
if(Request.ServerVariables["HTTP_CLUSTER_HTTPS"] != "on")
{
if(Request.ServerVariables.Get("HTTP_CLUSTER_HTTPS") == null)
{
string xredir__, xqstr__;
xredir__ = "https://" + Request.ServerVariables["SERVER_NAME"];
xredir__ += Request.ServerVariables["SCRIPT_NAME"];
xqstr__ = Request.ServerVariables["QUERY_STRING"];
if (xqstr__ != "")
xredir__ = xredir__ + "?" + xqstr__;
Response.Redirect(xredir__);
}
}
Response.Write("SSL Only");
}
</script>
<html>
<head id="head1" runat="server> <title>SSL Only</title> </head>
<body> </body> </html>