Tuesday, December 11, 2012

How to use HTTPS secure Page in URL in some Pages.


You may have to use https while Registration.

Please Add the Below code in Global.asax Page.

  protected void Application_BeginRequest(object sender, EventArgs e)
        {
            var currentUrl = System.Web.HttpContext.Current.Request.Url;
            if (currentUrl.AbsoluteUri.Contains("Registration"))
            {
                if (!currentUrl.Scheme.Equals(Uri.UriSchemeHttps, StringComparison.CurrentCultureIgnoreCase))
                {
                    //build the secure uri
                    var secureUrlBuilder = new UriBuilder(currentUrl);
                    secureUrlBuilder.Scheme = Uri.UriSchemeHttps;
                    //use the default port.
                    secureUrlBuilder.Port = string.IsNullOrEmpty(ConfigurationManager.AppSettings["HttpsPort"].ToString()) ? 443 : Convert.ToInt32(ConfigurationManager.AppSettings["HttpsPort"].ToString());
                    //redirect and end the response.
                    System.Web.HttpContext.Current.Response.Redirect(secureUrlBuilder.Uri.ToString());
                }
            }
        }

0 comments:

Post a Comment