Skip to main content

What is SSL and How SSL Works?

What is SSL?

SSL (Secure Sockets Layer) is a standard security technology for establishing an encrypted link between a web server and a browser. This link ensures that all data passed between the web server and browsers remain private and integral1.

How SSL Works

  1. Handshake Process: When a browser connects to a server, the SSL handshake process begins. This involves:

    • The browser requesting the server to identify itself.
    • The server sending a copy of its SSL certificate to the browser.
    • The browser checking the certificate against a list of trusted CAs (Certificate Authorities). If trusted, the browser creates, encrypts, and sends back a session key using the server’s public key.
    • The server decrypting the session key using its private key and establishing a secure encrypted connection.
  2. Data Encryption: Once the secure connection is established, all data transmitted between the browser and the server is encrypted using the session key. This ensures that even if the data is intercepted, it cannot be read without the session key.

Example: Implementing SSL in ASP.NET Core MVC with .NET 8

Step 1: Obtain an SSL Certificate

You need to obtain an SSL certificate from a trusted Certificate Authority (CA). This certificate will be used to encrypt the connection between the client and server.

Step 2: Configure Your Server

Depending on your hosting environment (IIS, Kestrel, Azure, etc.), configure your server to use the SSL certificate. For example, in IIS, you can bind the certificate to your website.

Step 3: Configure ASP.NET Core MVC Application

  1. Enforce HTTPS: Add the following code in your Program.cs to enforce HTTPS:
var builder = WebApplication.CreateBuilder(args);

// Enforce HTTPS
builder.Services.AddHttpsRedirection(options =>
{
    options.RedirectStatusCode = StatusCodes.Status307TemporaryRedirect;
    options.HttpsPort = 443;
});

var app = builder.Build();

app.UseHttpsRedirection();

app.MapGet("/", () => "Hello World!");

app.Run();
  1. Configure Kestrel (if using Kestrel server): Add the following configuration in your appsettings.json:
{
  "Kestrel": {
    "Endpoints": {
      "Https": {
        "Url": "https://localhost:5001",
        "Certificate": {
          "Path": "path/to/your/certificate.pfx",
          "Password": "your-certificate-password"
        }
      }
    }
  }
}

Step 4: Test Your Configuration

After setting up, test your configuration by accessing your application via HTTPS. Ensure that the browser shows a secure connection (usually indicated by a padlock icon).

Summary

SSL ensures secure communication by encrypting data between the client and server. Implementing SSL in an ASP.NET Core MVC application involves obtaining an SSL certificate, configuring your server, and enforcing HTTPS in your application.

For more detailed information, you can refer to the official Microsoft documentation on enforcing HTTPS in ASP.NET Core2 and configuring certificate authentication3.


Comments

Popular posts from this blog

Azure key vault with .net framework 4.8

Azure Key Vault  With .Net Framework 4.8 I was asked to migrate asp.net MVC 5 web application to Azure and I were looking for the key vault integrations and access all the secrete out from there. Azure Key Vault Config Builder Configuration builders for ASP.NET  are new in .NET Framework >=4.7.1 and .NET Core >=2.0 and allow for pulling settings from one or many sources. Config builders support a number of different sources like user secrets, environment variables and Azure Key Vault and also you can create your own config builder, to pull in configuration from your own configuration management system. Here I am going to demo Key Vault integrations with Asp.net MVC(download .net framework 4.8). You will find that it's magical, without code, changes how your app can read secretes from the key vault. Just you have to do the few configurations in your web config file. Prerequisite: Following resource are required to run/complete this demo · ...

How to Make a Custom URL Shortener Using C# and .Net Core 3.1

C# and .Net Core 3.1:  Make a Custom URL Shortener Since a Random URL needs to be random and the intent is to generate short URLs that do not span more than 7 - 15 characters, the real thing is to make these short URLs random in real life too and not just a string that is used in the URLs Here is a simple clean approach to develop custom solutions Prerequisite:  Following are used in the demo.  VS CODE/VISUAL STUDIO 2019 or any Create one .Net Core Console Applications Install-Package Microsoft.AspNetCore -Version 2.2.0 Add a class file named ShortLink.cs and put this code: here we are creating two extension methods. public   static   class   ShortLink {      public   static   string   GetUrlChunk ( this   long   key ) =>            WebEncoders . Base64UrlEncode ( BitConverter . GetBytes ( key ));      public   static   long   GetK...

Azure Logic Apps Send Email Using Send Grid Step by Step Example

Azure Logic Apps Send Email Using Send Grid Step by Step     Step 1- Create Send Grid Account Create a SendGrid Account  https://sendgrid.com/ Login and Generate Sendgrid Key and keep it safe that will be used further to send emails You can use Free service. it's enough for the demo purpose Step 2- Logic App Design Login to  https://portal.azure.com Go to Resources and Create Logic App Named "EmailDemo" Go To Newly Created Rosoure Named "EmailDemo" and Select a Trigger "Recurrence", You can choose according to your needs like HTTP, etc. Note* Without trigger you can not insert new steps or Actions Click on Change Connection and add Send Grid Key  Click on Create and Save Button on the Top. As we have recurrence so it will trigger according to our setup(every 3 months) so just for the test click on "RUN" button  Finally, you should get an email like below one: