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; /// /// Redirects a request to the HTTPS site. /// public class RedirectToHttpsModule : IHttpModule { #region Constants private const string HTTPS = "https"; #endregion #region IHttpModule Members public void Dispose() { // Nothing to dispose. } public void 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 }