【问题标题】:Web service auto-redirection to http or httpsWeb 服务自动重定向到 http 或 https
【发布时间】:2022-01-22 13:34:39
【问题描述】:

我刚刚将一个 C# Web 服务客户端从旧的 Web 服务更新到了新的服务,我相信它叫做 WCF?在旧的 web 服务中,有一个 AllowAutoRedirect 属性,可以自动从 http 重定向到 https。效果不好,但是还有一个 Url 属性,所以如果在 http 上连接失败,我可以编写代码将 URL 更改为 https 并重试。

在新的 WCF 方法中,有没有办法做到这一点?我是否必须添加对第二个服务的引用,地址相同,但 https?

(过去我在我的网站上打开和关闭了几次 SSL,我的现场软件必须自动处理这个问题,并使用任何可用的)。

【问题讨论】:

    标签: c# web-services wcf


    【解决方案1】:

    您可以通过添加重写规则来做到这一点。这会将来自 HTTP 的任何传入请求重写为 HTTPS。您可以查看下面的这些帖子以找到解决方案。

    <rule name="Redirect to HTTPS" stopProcessing="true">
      <match url="(.*)" />
      <conditions>
        <add input="{HTTPS}" pattern="^OFF$" />
      </conditions>
      <action type="Redirect" url="https://{HTTP_HOST}/{R:1}" redirectType="Permanent" />
    </rule>
    

    IIS redirect/rewrite .asmx service
    wcf webservice and URL forwarding with https
    HttpClient doesn't redirect even when AllowAutoRedirect = true
    Can i use a 301 redirect to allow an existing .Net Web service to keep functioning without requiring client updates?

    【讨论】:

    • 好主意。我没想到在服务器上做。这是一个更好的解决方案,谢谢。
    猜你喜欢
    • 1970-01-01
    • 2019-02-12
    • 1970-01-01
    • 2012-10-05
    • 2019-05-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-12-13
    相关资源
    最近更新 更多