// Redirect to HTTPS SiteResponse.Redirect("https://www.example.com");
using System;using System.Data;using System.Configuration;using System.Web;using System.Web.Security;using System.Web.UI;using System.Web.UI.WebControls;using System.Web.UI.WebControls.WebParts;using System.Web.UI.HtmlControls;/// <summary>/// Redirects a request to the HTTPS site. /// </summary>public class RedirectToHttpsModule : IHttpModule{ #region Constants private const string HTTPS = "https"; #endregion #region IHttpModule Members public void IHttpModule.Dispose() { // Nothing to dispose. } public void IHttpModule.Init(HttpApplication context) { context.BeginRequest += new EventHandler(context_BeginRequest); } void context_BeginRequest(object sender, EventArgs e) { HttpApplication application = sender as HttpApplication; if (!application.Request.IsSecureConnection) { // Grabs the current scheme, http, and replaces with https and redirects. application.Response.Redirect(application.Request.Url.ToString().Replace(application.Request.Url.Scheme, HTTPS)); } } #endregion}
<httpModules> <add type="RedirectToHttpsModule" name="RedirectToHttpsModule" /> </httpModules>
Remember Me
original dasBlog theme by Mads Kristensen altered by Donn Felker |
Disclaimer The opinions expressed herein are my own personal opinions and do not represent my employer's view in anyway.