---
title: "Force a Secure Connection (SSL) Using ASP.NET (MVC 3) in Cloud Sites"
source: "https://docs.nexcess.com/hosting/cloud-sites/website-management/ssl/force-a-secure-connection-ssl-using-asp-net-mvc-3-in-cloud-sites/"
description: "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."
vertical: "Hosting"
date: "2024-03-04"
last_modified: "2026-08-14"
---

# Force a Secure Connection (SSL) Using ASP.NET (MVC 3) in Cloud Sites

| ### **Note:** |
|---|
| The code provided below is only an example. Your specific website may require different code. As outlined in our [Terms of Service](https://www.liquidweb.com/policies/terms-of-service/) and [Cloud Sites Spheres of Support Expectations](https://www.liquidweb.com/help-docs/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](https://www.liquidweb.com/vps-hosting/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>
```
