How to force http to https using c# code
using System.Web;
public static void setSecureProtocol(bool bSecure)
{
string redirectUrl = null;
HttpContext context = HttpContext.Current;
if (bSecure && !context.Request.IsSecureConnection)
redirectUrl = context.Request.Url.ToString().Replace("http:", "https:");
if (redirectUrl != null)
context.Response.Redirect(redirectUrl);
}
protected void Page_Load(object sender, EventArgs e)
{
try
{
if (!IsPostBack)
{
setSecureProtocol(true);
}
}
finally
{
}
}
No comments:
Post a Comment
Thank you for your interest .