Using HTTPS in ASP.NET Core 2.0

Problem

How to ensure the use of HTTPS in ASP.NET Core.

Solution

Create an empty project and update Startup to add services and middleware for MVC, including the filter for HTTPS:

You could setup a redirect from HTTP to HTTPS on the web-server (e.g. IIS) or use middleware in ASP.NET Core:

Note: For testing in IIS Express, you can enable SSL from project Properties > Debug tab by checking the Enable SSL flag.

Source Code

GitHub: https://github.com/TahirNaushad/Fiver.Security.SSL

3 comments

    1. You could use a custom middleware to selectively redirect pages to HTTPS. I’ve not tried this with rewrite middleware. Would like to know if you’re able to do it through e.g. regular expressions using the rewrite middleware.

Leave a Reply