zoukankan      html  css  js  c++  java
  • asp.net 无法获取客户端请求的真实协议https

    问题:

    a) 客户端请求的是https,但服务端Request.Url获取的却是http;

    b) 负载均衡连接协议服务端与客户端协议不一致。

    有时候我们需要获取或拼接连接,但是可能会出现客户端使用https请求但我们获取的确是http的情况,这个时就无法访问拼接出来的http连接。

    这通常是由于服务器使用负载均衡造成客户请求使用的协议与服务端接收的协议不一致。

    解决办法:

    通过判断Request.ServerVariable["SERVER_PROTOCOL"] 是否等于HTTP/1.0来确定客户端真实请求的协议。

    string appUrl = Page.Request.Url.AbsoluteUri;
    if (Page.Request.ServerVariables["SERVER_PROTOCOL"] == "HTTP/1.0" && appUrl.StartsWith("http:", StringComparison.OrdinalIgnoreCase))
       appUrl = "https:" + appUrl.Substring(5);
  • 相关阅读:
    【SpringBoot】SpringBoot中请求路径问题
    CodeForces
    CodeForces
    7-36 旅游规划 (25 分(Dijkstra)
    CodeForces
    CodeForces
    CodeForces
    CodeForces
    CodeForces
    CodeForces
  • 原文地址:https://www.cnblogs.com/RedSky/p/7772300.html
Copyright © 2011-2022 走看看