Dotnet Core 2.1: Enable Https/SSL locally

As every developer wants to replicate local web development set up as per production environment as much as possible.

  1. Download and Install .Net Core 2.1 from this site.https://k10.in/
  2. Create new .Net core 2.1 web app
    https://k10.in/
  3. Use following commands to install certificates locally
  4. dotnet dev-certs https --help
    dotnet dev-certs https --trust

    https://k10.in/blogs/httpsdemo/3.png

  5. Read pop up and click yes to install certificate from localhost.
  6. Run your app, You will notice that your app is running on https locally.https://k10.in/blogs/httpsdemo/4.png
  7. By default HTTPS redirection is included in ASP.NET Core, and in Production it’ll use HTTP Strict Transport Security (HSTS) as well, avoiding any initial insecure calls.
    // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
  8. public void Configure(IApplicationBuilder app, IHostingEnvironment env)
    {
    if (env.IsDevelopment())
    {
    app.UseDeveloperExceptionPage();
    }
    else
    {
    app.UseExceptionHandler(“/Error”);
    app.UseHsts();
    }app.UseHttpsRedirection();
    app.UseStaticFiles();
    app.UseCookiePolicy();app.UseMvc();
    }

References:

https://docs.microsoft.com/en-us/aspnet/core/release-notes/aspnetcore-2.1?view=aspnetcore-2.1

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s