Asp.Net Core中的SSL不起作用 [英] SSL in Asp.Net Core doesn't work

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

问题描述

我从Visual Studio Web Application(Net.Core)模板创建了一个简单的Web应用程序,并获得了单独的用户帐户授权.

然后,我在 Project-> MyProject属性... 中启用了SSL,并将带有https的URL复制到App Url.

最后,我添加了:

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

启动.

它不起作用!当我启动应用程序时,它只是在一秒钟后关闭,什么也没有发生,没有错误,什么都没有!

Asp.Net Core中的SSL有什么问题,如何正确启用它?

解决方案

对于开发测试,您需要首先启用SSL.

右键单击项目>属性">调试"

  • 在配置文件中选择"IIS Express"
  • 选中启用SSL"

如果调试在启动后停止(未找到进程ID),则必须将IIS Express自签名证书安装到证书存储中.

您可以遵循本指南

  • 文件>添加管理单元>选择证书">添加>计算机帐户>下一步>完成
  • 点击确定
  • 转到个人/证书".寻找本地主机" Zertificate
  • 拖动&将证书放到受信任的根证书颁发机构"
  • 关闭MMC.重新启动Visual Studio 2015
  • 现在,您应该可以对其进行调试了.

    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?

    解决方案

    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.

    这篇关于Asp.Net Core中的SSL不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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