Reputation: 10115
Does it need Certificate/License/Registration
before launching the website using https
?
I want to use the mentioned code in Global.asax
file.
protected void Application_BeginRequest(Object sender, EventArgs e)
{
Response.Redirect("https://" + Request.ServerVariables["HTTP_HOST"]
+ HttpContext.Current.Request.RawUrl);
}
Upvotes: 0
Views: 1142
Reputation: 75113
First of all, I think you will never reach it, as it will loop in the Application_BeginRequest
over and over as you are redirecting all requests...
Maybe what you're after is redirecting if the request comes from a non secure connection (http), no?
for that, see if the request comes from such connection like:
protected void Application_BeginRequest(object sender, EventArgs e)
{
if (!HttpContext.Current.Request.IsSecureConnection)
Response.Redirect(HttpContext.Current.Request.Url.AbsoluteUri.Replace("http://", "https://"));
}
Secondly, the HTTPS protocol needs to be up and running or you will get a ERR_SSL_PROTOCOL_ERROR
error thrown.
In Visual Studio, you can easily enable https in the project properties
and you will get the untruest warning
As Visual Studio generated (on installation) a default self signed certificated.
In production environment you will need to:
From your comments I have some question myself now...
Upvotes: 1
Reputation: 499352
When you want to use secure HTTP (using the HTTPS protocol) you say that the traffic between the browser and server is encrypted.
This means you need a certificate on the server so that the browser and server can decide on how to encrypt the traffic.
This has nothing to do with redirects and everything to do with your server setup.
Upvotes: 0