如何在命令行中使用HTTPS启动IIS Express并指定路径?

10
能否使用命令行启动IIS Express并包含HTTPS绑定?需要使用/path参数。
3个回答

12

脚本部分的又一篇:

IisExpressAdminCmd setupSslUrl -url:https://localhost:44308 -UseSelfSigned

appcmd add site /name:"MySite" /bindings:https/*:44308:localhost /physicalPath:"C:\MySite"

iisexpress /site:MySite

这些命令在C:\Program Files (x86)\IIS Express\目录中。


这很棒。如果您有多个站点怎么办?如何在同一池中启动它们? - DAG

4
  1. Following link would help you in configuring https port (especially read "Making an SSL Cert, hooking it up to IIS Express and making it Trusted" from this link ) https://www.hanselman.com/blog/WorkingWithSSLAtDevelopmentTimeIsEasierWithIISExpress.aspx

  2. When /path command line option is used, IIS Express uses the template appliationhost.config file located in %programfiles%\IIS Express\AppServer (on 64-bit machine %programfiles(x86)%\IIS Express\AppServer). Edit binding element in this configuration file as shown below (change the protocol to 'https')

    <binding protocol="https" bindingInformation=":8080:localhost" />
    
  3. Now from the IIS Express installation folder, run iisexpress.exe /path:"<path-to-your-web-application>" /port:<HTTPS-port-configured-in-step-1>


这个方案同时适用于HTTP和HTTPS绑定吗?只需要添加另一个<binding>节点即可吗? - Bob Banks
3
不行,也许你应该使用/config命令行开关。 - vikomall
谢谢,但我想尝试完全通过命令行完成,而不是编辑配置文件。听起来好像做不到。 - Bob Banks

2

我也曾遇到过这个问题。虽然不是你所期望的完美解决方案,但你可以通过命令行向默认的iisexpress配置中添加一个新站点:

APPCMD add site /name:MyNewSite /bindings:"http/*:81:" /physicalPath:"C:\MyNewSite"

您需要定位c:\program files (x86)\iis express中的appcmd.exe。
添加后,您可以使用iisexpress.exe以传统方式启动,将其定位到刚刚添加到配置文件中的站点。
您需要“允许”iisexpress提供ssl服务。
不过,编写自定义配置文件以加载所需绑定并使用该文件加载站点可能更容易/更清晰。这样控制更多。
参考链接:使用ADD、SET和DELETE操纵对象使用IISExpress更轻松地进行开发时SSL操作

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接