Tuesday, May 09, 2017 5:51 PM Indraneel Pole

ASP.NET Core Error : Authorization failed for the request at filter 'Microsoft.AspNetCore.Mvc.RequireHttpsAttribute'

 

Behavior / Steps to reproduce

Running ASP.NET Core application on Kestrel Web Server. Every time the app is run, it makes a strange redirect to “https”, and the call doesn’t work. In console you see the following error.

 

image

Notice : This error doesn’t occur while running on IIS Express.

Explanation

This happens if in your startup file you have services configured with filters to have only Https attributes

image

This will require you to have local certificate. In case of IIS Express, IIS Express takes care of it for you. However, for other web server such as Kestrel this doesn’t work.

How to fix this

If you are just testing locally, you can simply comment this filter out, and everything will work. However, if you have to use the SSL, you should create a certificate and use it in your code. How to create Certificate is explained in this awesome post. To use it in your app, you need to call this certificate in your app, and configure this certificate in your WebHostBuilder as shown in this Answer.

Leave a Comment

(required) 
(required) 
(optional)
(required)