在Visual Studio中启用SSL [英] Enable SSL in Visual Studio

查看:743
本文介绍了在Visual Studio中启用SSL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经在Visual Studio中启用了SSL,如下所示:





我还设置了以下内容:





当我通过IE(通过Visual Studio调试)访问网站时,会看到以下内容:





当我通过Firefox(通过Visual Studio调试)访问网站时,会看到以下内容:





没有选择可以通过Firefox或IE进入网站。我花了整整一天的时间来了解问题所在。我在做什么错?

解决方案

假设您有一个.NET MVC或Web API项目,并且您想运行它在SSL上。换句话说,您想使用类似于



同一属性窗口还将显示应用程序的HTTPS URL。在上面的示例中,它是



启动应用程序。您可能会在浏览器中收到一条消息,指出不信任本地主机地址,如果您继续访问该网站,后果自负。这是瑞典语的Chrome示例:





您会在个人下方的同一管理单元中看到一个文件夹。那么我们该怎么做呢?
右键单击证书,然后从上下文菜单中选择所有任务,导出...。在证书导出向导上,单击下一步。保持不导出私钥选项不变,单击下一步。在下一个屏幕上接受默认设置,即 DER编码的二进制X.509应保持选中状态,然后单击下一步。然后,您需要提供导出文件的名称和位置。将其命名为 localhost,并将其保存在容易找到的位置。单击下一步,然后单击完成。应该有一个弹出消息,说明导出成功。
接下来,右键单击名为受信任的根证书颁发机构的文件夹,然后从上下文菜单中选择所有任务,导入...。在证书导入向导中保持本地计算机选项不变,然后单击下一步。浏览到您之前保存的证书。单击下一步,并接受所有默认值,直到到达向导末尾。应该有一条消息说导入成功。
如果现在返回个人存储并双击localhost证书,则应该看到该证书是受信任的:





好的,让我们再次启动.NET Web项目,打开的页面应该没有任何警告地打开。如果您仍然看到相同的问题,请对其进行全新的浏览器会话测试,例如此处是IE:





您可以还可以从浏览器窗口查看提取的证书。这是来自IE的示例:




I have enabled SSL in Visual Studio as shown below:

I have also set the below:

When I access the website via IE (via Visual Studio debugging) I see this:

When I access the website via Firefox (via Visual Studio debugging) I see this:

There is no option to progress to the website in either Firefox or IE. I have spent all day trying to understand what is wrong. What am I doing wrong?

解决方案

Say you have a .NET MVC or Web API project and you’d like to run it on SSL. In other words you’d like to start up the project on a URL similar to https://localhost:xxxx. The first step is easy. You just select the MVC/Web API project name in the solution and locate the property called "SSL Enabled" in properties window:

The same properties window will also show the HTTPS url for the application. In the above example it’s https://localhost:44300/. Copy that URL and go to the project properties window. Locate the Web tab and override the Project Url property with the https address:

Start the application. You’ll likely get a message in the browser saying that the localhost address is not trusted, you can continue to the website at your own risk. Here’s a Chrome example in Swedish:

The problem is that the certificate that was installed automatically for you by Visual Studio is not trusted. You can locate the certificate in the Personal folder of the computer-level certificates in the certificates snap-in:

If you double-click the certificate you’ll see that it’s not trusted:

The message also provides the solution: the certificate must be imported into the trusted root certification authorities folder. You’ll see that as a folder in the same snap-in just below "Personal". So how can we do that? Right-click the certificate, then select All Tasks, Export… from the context menu. Click Next on the certificate export wizard. Leave the "Do not export the private key" option untouched, click Next. Accept the default on the next screen, i.e. "DER encoded binary X.509" should stay selected, then click Next. Then you’ll need to provide a name and a location for the exported file. Call it "localhost" and save it in a location where you can easily find it. Click Next and the Finish. There should be a popup message saying that the export was successful. Next right-click the folder called Trusted Root Certification Authorities and select All Tasks, Import… from the context menu. Leave the "Local Machine" option untouched in the certificate import wizard, click Next. Browse to the certificate you saved just before. Click Next and accept all the default values along the way until you reach the end of the wizard. There should be a message saying that the import was successful. If you now go back to the Personal store and double-click the localhost certificate then you should see that it’s trusted:

OK, let’s start the .NET web project again, the opening page should open without any warning. If you still see the same issue then test it a brand new browser session, e.g. here in IE:

You can also view the extracted certificate from the browser window. Here’s an example from IE:

这篇关于在Visual Studio中启用SSL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆