April 2018
Intermediate to advanced
300 pages
7h 41m
English
To enable SSL in our ASP.NET Core project, we can add filters in the AddMvc method defined in the ConfigureServices method of our Startup class. Filters are used to filter the HTTP calls and take certain actions:
services.AddMvc(options =>
{
options.Filters.Add(new RequireHttpsAttribute())
});
Filters added in the AddMvc method are global filters and interrupt all HTTP requests, irrespective of a specific controller or action. We added the RequireHttpsAttribute filter, which validates the incoming request and checks whether the request is on HTTP or HTTPS. If the request is on HTTP, it will auto redirect the request to HTTPS and use the default port, which is 443 in the case of HTTPS. Adding the ...