【问题标题】:How to specify port when using ssl with IIS Express?在 IIS Express 中使用 ssl 时如何指定端口?
【发布时间】:2013-01-01 18:08:14
【问题描述】:

使用 vs2012、.net 4.5、mvc4。我的项目有部分在 ssl 下。 我在 IIS Express 下运行我的项目。在项目属性中:

>SSL Enabled: True
>SSL Url: https://localhost:44300/
>URL: http://localhost:18000/

项目运行良好。如果您按 F5,浏览器将打开并显示位于 >http://localhost:18000/ 的站点 并且所有常规(http)页面都可以正常工作。 但是如果您点击登录页面的链接,例如,受 ssl 保护(控制器中的 [RequireHttps]),它会尝试转到

>https://localhost/Account/LogOn

这是不正确的,因此在 404 上失败。 如果你手动去

>https://localhost:44300/Account/LogOn 

登录页面工作正常。 问题是:当需要 https 时,如何使事物转到正确的地址?

【问题讨论】:

    标签: asp.net-mvc ssl iis-express


    【解决方案1】:

    用这样的重写标签配置你的 web.config 文件:

    <rewrite>
      <rules>
        <rule name="Secure Account Controller" enabled="true" stopProcessing="true">
          <match url="^account" ignoreCase="true">
            <conditions logicalGrouping="MatchAll" trackAllCaptures="true">
              <add input="{HTTPS}" pattern="off"/>
              <add input="{HTTP_HOST}" pattern="([^/:]*?):[^/]*?"/>
            </conditions>
            <action type="Redirect" url="https://{c:1}:44300{URL}"/>
          </match>
        </rule>
      </rules>
    </rewrite>
    

    以上代码可以通过IIS面板轻松生成。

    【讨论】:

    • 这应该添加到&lt;system.webServer&gt; 部分吗?当我复制/粘贴代码并运行该站点时,我收到 500.52 URL RewriteModule 错误(无法识别的元素“条件”)。我认为 &lt;conditions&gt; 不应该嵌套在 &lt;match&gt; 标签内。
    • 另一个“问题”是,在此之后,如果您单击登录页面上的任何链接,您将继续使用https。也许这是标准行为,但我只想将 https 用于 Account 控制器的视图。
    • 是的。把它放在 。您还必须通过 SSL 准备 url 内容和控制器操作。 foreach 控制器操作需要 ssl put [RequireHttps] 语句。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多