Recently I got to do this when one of our site was hosted on Go Daddy Hosted Server. They don’t have SSL redirect functionality for Windows environment, so we need to write some script to support this.
I have done something like this by writing few lines of code in Global.asax file in your web project.
void Application_BeginRequest(Object sender, EventArgs e)
{
if (ConfigurationManager.AppSettings["APIEnvironment"].ToUpper() == "LIVE"
&& Request.ServerVariables["HTTP_HOST"].ToString().ToLower().Trim() != "localhost") // turn the mode OFF in development
{
if (HttpContext.Current.Request.IsSecureConnection.Equals(false))
{
Response.Redirect("https://" + Request.ServerVariables["HTTP_HOST"] + HttpContext.Current.Request.RawUrl);
}
}
}
No comments:
Post a Comment