Pankaj
Pankaj

Reputation: 10115

Difference between http and https technique

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

Answers (2)

balexandre
balexandre

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

enter image description here

and you will get the untruest warning

enter image description here

As Visual Studio generated (on installation) a default self signed certificated.

In production environment you will need to:

  • if it's an intranet application, just use the self-signed certificate
  • on a internet application, you do need to buy an SSL certificates, now-days they re cheaper and cheaper...

From your comments I have some question myself now...

  • Do you understand what HTTPS does to the connection between client computer and server?
  • Do you really need a secure connection between the two?
  • What kind of data are you trying to secure?

Upvotes: 1

Oded
Oded

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

Related Questions