Enable Ssl in Visual Studio

Enabling SSL in Visual Studio 2017

The SSL setting is at a different place in ASP.NET and ASP.NET Core projects. The following screenshots come from my blog: https://www.meziantou.net/2016/10/09/iis-express-ssl

ASP.NET

Sample Image

ASP.NET Core

Sample Image

Setting up SSL certificate in Visual Studio

If anyone has this very specific issue again, I'll post what I did to fix it (from this forum thread: https://developercommunity.visualstudio.com/t/cant-debug-aspnet-applications-err-connection-rese/1239592?viewtype=all)

1. In VS: Tools > Command Line > Developer Command Prompt, run devenv /resetsettings (this will also reset some customization settings)
Edit: not needed, thanks lex-li!


  1. Remove potentially malformed certificates:
  • In User Certificate Manager (certmgr.msc) AND Computer Certificate Manager (certlm.msc):
  • Personal > Certificates > if a localhost certificate exists there, delete it
  • Trusted Root Certification Authorities > Certificates > if a localhost certificate exists, delete it

  1. Repair IIS 10.0 Express:
  • Control Panel > Programs & Features > Right Click IIS Express > Repair
  • It will ask for a file path o a .msi installation file, but VS doesn't store one for IIS Express
  • Look for a hidden file _package.json in the directory C:\ProgramData\Microsoft\VisualStudio\Packages\Microsoft.VisualStudio.IISExpress.Msi,version=xx.xx.xxxxx.xxx,chip=x64
  • Copy the "url" (which should point to the correct .msi file) in _package.json into the file path asked for by the Repair prompt
  • Verify the repair worked by running netsh http show sslcert ipport=0.0.0.0:44390 in the command prompt (ensure the Certificate Hash field is present).

  1. Restart Visual Studio, debug your application, you should get the same Trusted Certificate prompt you misclicked the first time.
    (You can check the User Certificate Manager to see a new localhost certificate has been installed correctly)

Enable SSL in Visual Studio - not prompted to install certificate

Configuring of IIS Express to use SSL consist from many steps, which are a little tricky at the first usage. The most important parts, which one have to do, are the following:

  • create/get/generate SSL certificate. One can use MakeCert.exe for example to generate self-signed certificate. Look at %ProgramFiles(x86)%\Windows Kits\10\bin\x64 or %ProgramFiles(x86)%\Windows Kits\8.1\bin\x64 for the MakeCert.exe utility. The certificate have to be imported in "Trusted Root Certification Authorities" or "Third-Party Root Certification Authorities" additionally to make it trusted on the local computer (or for the local user).
  • IIS Express uses underlying HTTP.SYS of the operation system to process all HTTP/HTTPS requests. Thus one have to configure it, for example, by usage netsh http add sslcert ... and netsh http add urlacl ... or by using of "%ProgramFiles%\IIS Express\IisExpressAdminCmd.exe" utility with setupFriendlyHostnameUrl parameter.
  • configure Visual Studio project to use HTTPS for debugging and to create binding with HTTPS for IIS Express. One can run IIS Express in general without Visual Studio. Then including of new <binding> issue for the web site should be included in %USERPROFILE%\Documents\IISExpress\config\applicationhost.co‌​‌​‌​nfig. If one uses IIS Express only inside of Visual Studio, then the corresponding binding will be inserted by Visual Studio in the $(solutionDir)\.vs\config\applicationhost.config file.

I'd recommend you to read and to follow the old article posted by Hanselman in 2011. The information is still guilty today.

This site can’t provide a secure connection' Enable SSL configure for Visual Studio 2019

try another port, like this url

https://localhost:44337/

Me too had problem with 58061.

Try one of these:

44337,44338,44339, ..... 44399

The probable cause is that 44300-44399 are preconfigured by IIS Express installer with a test certificate, while other ports might not.

How to enable SSL for IIS Express in VS2015

Edit your applicationhost.config in [SOLUTION_DIR]\.vs\config

for exemple in the sites section :

<site name="YOUR SITE NAME" id="1">
<application path="/" applicationPool="Clr4IntegratedAppPool">
<virtualDirectory path="/" physicalPath="YOUR SITE PATH" />
</application>
<bindings>
<binding protocol="http" bindingInformation="*:80:localhost" />
<binding protocol="https" bindingInformation="*:44300:localhost" />
</bindings>
</site>


Related Topics



Leave a reply



Submit