https和http 调用过程中请求头 referrer 获取不到的问题
HTTP协议规定:
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:
<input id="referrer" type="hidden" name="referrer" />
<script type="text/javascript">
document.getElementById("referrer").value = window.location.href
</script>
2、后台:
string urlReferrer = "";
if (Request.UrlReferrer == null)
{
urlReferrer = Request["referrer"];
- }
else
{
urlReferrer = Request.UrlReferrer.AbsoluteUri;
}