Yurii N.
Yurii N.

Reputation: 5703

SSL in Asp.Net Core doesn't work

I created a simple web application from visual studio Web Application(Net.Core) template with individual user account authorization.

Then, I enabled SSL in Project->MyProject Properties..., copied URL with https to App Url.

Finally, I added:

services.AddMvc(options =>
{
    options.Filters.Add(new RequireHttpsAttribute());
});

to Startup.

And it doesn't work! When I'm starting the application, it just simply turns off after a second, and nothing happens, no error, nothing!

What's wrong with SSL in Asp.Net Core, and how can I enable it correctly?

Upvotes: 8

Views: 41768

Answers (1)

Tseng
Tseng

Reputation: 64121

For development testing you need to enable SSL first.

Right click the project > Properties > Debug

  • Choose "IIS Express" in profile
  • Check "Enable SSL"

If your debugging stops after starting (no process ID found), then you have to install the IIS Express self-signed certificate into the certificate store.

You can follow this guide here. It's bit older but still applies to Visual Studio 2015. It's due to a bug in Update 3 where IIS Certificate isn't installed in the trusted certificate storage correctly.

Alternatively,

  1. hit Win+R, type run "mmc.exe"
  2. File > Add Snap-in > Choose "Certificates" > Add > Computer Account > Next > Finish
  3. Hit OK
  4. Go to "Personal/Certificates". Look for "localhost" Zertificate
  5. Drag & Drop the certificate to "Trusted Root Certification Authorities"
  6. Close the MMC. Restart Visual Studio 2015

Now you should be able to debug it.

Upvotes: 20

Related Questions