Friday, September 16, 2011

Enable SSL in asp.net



Please Create this function to enable SSL on your site with some page but make sure the SSL certificate is already installed
on your site or server and then call this function on page load event. 



Private void EnableSSL()
    {
        String CurrentUrl = Request.Url.ToString();
        //Get absolute path
        String sPath = System.Web.HttpContext.Current.Request.Url.AbsolutePath;
        System.IO.FileInfo Finfo = new System.IO.FileInfo(sPath);
        string page=
Finfo.Name;
        if (
page== "abc.aspx" || page== "cde.aspx" )
        {
            String NewUrl = "";
            if (!Request.IsSecureConnection)
            {
                NewUrl = "https" + CurrentUrl.Substring(4);
                Response.Redirect(NewUrl);
            }
        }
        else
        {
            if (CurrentUrl.IndexOf("https") >= 0)
            {
                Response.Redirect(CurrentUrl.Replace("https", "http"));
            }
        }
    }









No comments:

Post a Comment