Greg
Greg

Reputation: 2690

aspnet core error: Authorization failed for the request at filter 'Microsoft.AspNetCore.Mvc.RequireHttpsAttribute'

I am building and testing a aspnet core app using SSL. Running the site in IIS Express works fine. So, I thought I might see what's required to get it running on IIS 10. As expected, there are a few issues.

First off, I need to clarify that I have successfully hosted a non SSL aspnet app in IIS, so all the bits needed for an aspnet core app are there. But in the case of a SSL app, all I get is a message in the browser saying that an error occurred. Also nothing useful in the webserver logs.

So, my first test was to try and run the app directly in the published folder using dotnet xxx.dll. That's when I noticed the authorization error.

 services.Configure<MvcOptions>(options =>
  {
    options.Filters.Add(new RequireHttpsAttribute());
  });

enter image description here

enter image description here

Upvotes: 2

Views: 4298

Answers (1)

Greg
Greg

Reputation: 2690

I solved the issue by generating a pfx certificate as explained on Shawn Wildermuth's blog (https://wildermuth.com/2016/10/26/Testing-SSL-in-ASP-NET-Core). Once this is done, modify your Program.cs file as follows:

enter image description here

Once this is done,re publish your project (command: dotnet publish)and move the pfx file into the published folder.

Now, when you run dotnet MyFileName.dll in the published folder, it can access the cert and everything works. ( Well it did for me )

Upvotes: 1

Related Questions