Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>You have basically two options.</p> <p>If you want all authenticated pages to run under SSL, you can set the requireSSL="true" attribute on forms authentication. Just make sure your login page is also running on HTTPS.</p> <p>You can also set this on a page-by-page basis. I found this works well in a "page base" class that inherits from System.Web.UI.Page, and that all your pages inherit from (instead of System.Web.UI.Page).</p> <pre><code>public class PageBase : System.Web.UI.Page { public bool RequiresSSL {get; set;} string currentPage = Request.Url.ToString(); public PageBase() { Init += new EventHandler(PageBase_Init); } void PageBase_Init(object sender, EventArgs e) { if ((RequiresSSL) &amp;&amp; (WebConfigurationManager.AppSettings["SSLavailable"] == "true")) { if (currentPage.ToLower().StartsWith("http://")) { redirectTo = "https://" + currentPage.Substring(7); Response.Redirect(redirectTo); } } else { if (currentPage.ToLower().StartsWith("https://")) { redirectTo = "http://" + currentPage.Substring(8); Response.Redirect(redirectTo); } } } } </code></pre> <p>The AppSettings value of SSLavailable allows you to switch the whole mechanism off when you're running in test mode without SSL.</p> <p>For pages that need to run in SSL mode, all they need to do is set RequiresSSL:</p> <pre><code>public partial class ChangePassword : PageBase { public ChangePassword() { PreInit += new EventHandler(ChangePassword_PreInit); } void ChangePassword_PreInit(object sender, EventArgs e) { RequiresSSL = true; } } </code></pre> <p>It works, very smoothly, and any other pages they go to after the secure page will automatically switch back to HTTP protocol.</p>
 

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