SSL Connection / Connection Reset with IISExpress

2020-01-24 10:43发布

I'm using the new Visual Studio 2013 with IISExpress for the first time (previously used ASP.net Development server on VS2010). I'm running into issues trying to debug my project.

This is what I see in Chrome:

Unable to make a secure connection to the server. This may be a problem with the server, or it may be requiring a client authentication certificate that you don't have. Error code: ERR_SSL_PROTOCOL_ERROR

I updated my Properies -> web file so that the Project Url uses a https URL now. However, after doing that, I now get a new error when launching:

The connection to localhost was interrupted. Error code: ERR_CONNECTION_RESET

Thanks

19条回答
何必那么认真
2楼-- · 2020-01-24 10:51

I was having this problem, I had configured my site for global require https in FilterConfig.cs.

public static void RegisterGlobalFilters(GlobalFilterCollection filters)
    {
        filters.Add(new HandleErrorAttribute());
        filters.Add(new RequireHttpsAttribute());
    }

I had forgotten to change the project url to https: from this tutorial http://azure.microsoft.com/en-us/documentation/articles/web-sites-dotnet-deploy-aspnet-mvc-app-membership-oauth-sql-database/ under ENABLE SSL part 4. This caused the errors you were getting.

查看更多
走好不送
3楼-- · 2020-01-24 10:52

Another problem that happened me twice:
In IIS Express's applicationhost.config the order of the bindings does matter. One binding could take precedence over your SSL binding, making it not working.

Example:

<site name="MySite007" id="1">
    <application path="/" applicationPool="Clr4IntegratedAppPool">
        <virtualDirectory path="/" physicalPath="C:\Users\myuser\projects\mysolutionfolder\MyProject.Service" />
    </application>
    <bindings>
        <binding protocol="http" bindingInformation=":8081:localhost" />
        <binding protocol="http" bindingInformation=":8080:" /><!-- evil binding -->
        <binding protocol="https" bindingInformation="*:44327:localhost" />
    </bindings>
</site>

You may have added a binding similar to the second one to be able to access your WebService from outside localhost. Because this binding listens on any adress, it seems to override the SSL binding although a different port was used.

Remove the evil binding or move it down.

查看更多
老娘就宠你
4楼-- · 2020-01-24 10:53

Make sure to remove any previous 'localhost' certificates as those could conflict with the one generated by IIS Express. I had this same error (ERR_SSL_PROTOCOL_ERROR), and it took me many hours to finally figure it out after trying out many many "solutions". My mistake was that I had created my own 'localhost' certificate and there were two of them. I had to delete both and have IIS Express recreate it.

Here is how you can check for and remove 'localhost' certificate:

  • On Start, type -> mmc.exe
  • File -> Add/Remove Snap-in...
  • Select Certificates -> Add> -> Computer account -> Local computer
  • Check under Certificates > Personal > Certificates
  • Make sure the localhost certificate that exist has a friendly name "IIS Express Development Certificate". If not, delete it. Or if multiple, delete all.

On Visual Studio, select project and under property tab, enable SSL=true. Save, Build and Run. IIS Express will generate a new 'localhost' certificate.

Note: If it doesn't work, try these: make sure to disable IIS Express on VS project and stopping all running app on it prior to removing 'localhost' certificate. Also, you can go to 'control panel > programs' and Repair IIS Express.

查看更多
家丑人穷心不美
5楼-- · 2020-01-24 10:53

I have a same problem in Visual Studio 2015. Because I use SSL binding in web.config

<rewrite>
   <rules>   
     <rule name="HTTP to HTTPS Redirect" stopProcessing="true">
       <match url="(.*)" />
       <conditions>
          <add input="{HTTPS}" pattern="off" />
       </conditions>
          <action type="Redirect" url="https://{HTTP_HOST}/{R:1}" redirectType="Found" />
     </rule>
   </rules>
</rewrite>

And I can fix the problem with the answer of Mr.djroedger. By replacing

<add input="{HTTPS}" pattern="off" />

with

<add input="{HTTP_HOST}" pattern="localhost" negate="true" />

into my web.config, so my code is

<rewrite>
  <rules>   
    <rule name="HTTP to HTTPS Redirect" stopProcessing="true">
      <match url="(.*)" />
      <conditions>
         <add input="{HTTP_HOST}" pattern="localhost" negate="true" />
      </conditions>
         <action type="Redirect" url="https://{HTTP_HOST}/{R:1}" redirectType="Found" />
    </rule>
 </rules>
</rewrite>
查看更多
Ridiculous、
6楼-- · 2020-01-24 10:56

The 'Digicert certificate installation checker' is often helpful in situations like this.

I was able to verify the SSL cert being attempted was the one I was expecting by comparing the serial number.

enter image description here

For me @Jason Kleban answer was the actual problem, but this can be a very useful utility to check your basic assertions about what certificate is being loaded.

查看更多
Rolldiameter
7楼-- · 2020-01-24 10:57

If you're using URLRewrite to force SSL connections in your web.config, it's probably rewriting your localhost address to force https. If debugging with SSL enabled isn't important to you and you're using URLRewrite, consider adding <add input="{HTTP_HOST}" pattern="localhost" negate="true" /> into your web.config file's rewrite section. It will stop the rewrite for any localhost addresses but leave it in place in a production environment. If you're not using URLRewrite or need to debug using SSL, http://www.hanselman.com/blog/WorkingWithSSLAtDevelopmentTimeIsEasierWithIISExpress.aspx might help. It's for VS2010, but should suffice for VS2013 as well.

查看更多
登录 后发表回答