Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I usually do this in the OnPreLoad event to force SSL:</p> <pre><code>protected override void OnPreLoad(EventArgs e) { base.OnPreLoad(e); String qs; qs = Request.QueryString; //// Force the page to be opened under SSL if (!Request.IsSecureConnection) { if (qs != "") { qs = "?" + qs; } Response.Redirect("https://" + Request.ServerVariables["SERVER_NAME"].ToString() + Request.ServerVariables["PATH_INFO"].ToString() + qs); } } </code></pre> <p>If you want to force SSL for all pages, it may be a good fit for an HttpModule. I have come up with the following:</p> <pre><code>using System; using System.Web; namespace CustomHttpModules { public class EnforceSSLModule : IHttpModule { public void Init(HttpApplication httpApp) { httpApp.PreRequestHandlerExecute += this.OnPreRequestHandlerExecute; } public void Dispose() { } public void OnPreRequestHandlerExecute(object o, EventArgs e) { using (HttpApplication httpApp = (HttpApplication)o) { if (HttpContext.Current != null) { HttpContext ctx = HttpContext.Current; String qs; qs = ctx.Request.QueryString; //// Force the page to be opened under SSL if (ctx.Request.IsSecureConnection) { if (qs != "") qs = "?" + qs; ctx.Response.Redirect("https://" + ctx.Request.ServerVariables["SERVER_NAME"].ToString() + ctx.Request.ServerVariables["PATH_INFO"].ToString() + qs); } } } } } } </code></pre> <p>To use the HttpModule in IIS5.1 or IIS6, drop the compiled assembly for the HttpModule in your site's bin folder and add the following to your web.config's HttpModules section:</p> <pre><code>&lt;add type="CustomHttpModules.EnforceSSLModule, dllname" name="EnforceSSLModule" /&gt; </code></pre> <p>(where <strong>dllname</strong> is the name of your assembly file without the extension)</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload