https和http 调用过程中请求头 referrer 获取不到的问题

HTTP协议规定:
  1. Clients SHOULD NOT include a Referer header field in a (non-secure) HTTP request if the referring page was transferred with a secure protocol.

解决办法:
1、表单添加一个字段referrer,如果头部没有Referer,则获取表单的这个字段,
     添加js:
  1. <input id="referrer" type="hidden" name="referrer" />
  2. <script type="text/javascript">
  3. document.getElementById("referrer").value = window.location.href
  4. </script>

2、后台:
  1. string urlReferrer = "";
  2. if (Request.UrlReferrer == null)
  3. {
  4. urlReferrer = Request["referrer"];
  5. }
  6. else
  7. {
  8. urlReferrer = Request.UrlReferrer.AbsoluteUri;
  9. }







posted @ 2016-10-17 12:05  Tom.汤  阅读(1379)  评论(0编辑  收藏