在 IIS Express 中为 MVC Web 应用程序强制在端口 443 上使用 SSL

问题描述 投票:0回答:2

我有一个 MVC 5 Web 应用程序,我需要使用 SSL 来运行其中的部分(登录、帐户管理等)。我为 Web 项目启用了 SSL,更改了

applicationhost.config
:

中的绑定
<bindings>
    <binding protocol="http" bindingInformation="*:80:example.com" />
    <binding protocol="https" bindingInformation="*:443:example.com" />
</bindings>

但是,当我重新启动 IIS Express 并运行该站点时,它会将 SSL 端口覆盖为 44300。有什么办法让它保持在 443 吗?

asp.net asp.net-mvc ssl iis-express
2个回答
4
投票
  1. netsh http show sslcert
    。在输出中搜索
    port 44300
    条目并复制
    certhash
    appID
    值。

  2. 删除 44300 的条目:

    netsh http delete sslcert ipport=0.0.0.0:44300

  3. 使用步骤 1 中的 certhash 和 appID 添加端口 443 的新条目:

    netsh http add sslcert ipport=0.0.0.0:443 certhash=<certhash> appid=<appid>

如果您在 Powershell 中运行此命令,则需要将参数用单引号引起来,因此上面步骤 3 中的命令将变为

netsh http add sslcert 'ipport=0.0.0.0:443' 'certhash=<certhash>' 'appid=<appid>'

在http.sys中配置条目后,需要重新启动http服务才能使更改生效。

net stop http
net start http

从 Powershell 中,您可以像这样重新启动服务:

Restart-Service http

0
投票

考虑到您已经映射了正确的绑定。右键单击 Web 应用程序虚拟目录 -> 管理应用程序 -> 高级设置 -> 启用协议,使您的应用程序能够在 IIS 中使用

https

在 FeaturedView 窗格中单击

SSL Settings

 并选中显示 
Require SSL
 的框,然后单击应用。

您可能还想查看此现有帖子

IIS Express 在启用 SSL 时默认使用 https 端口 44300

© www.soinside.com 2019 - 2024. All rights reserved.