Reputation: 2901
I have a website that runs under https.
I'm trying to find if an internal page was the referrer to the current page, do some stuff selectively.
Here's the code that I'm testing with:
if (Request.UrlReferrer != null && Request.UrlReferrer.Host == Request.Url.Host)
{
Response.Write(Request.UrlReferrer.OriginalString + "<br>");
Response.Write(Request.UrlReferrer.AbsoluteUri + "<br>");
Response.Write(Request.Headers["Referer"] + "<br>");
}
The code correctly traps internal requests however, the variables that are outputted only ever contain the base domain - https://example.com/
and not the expected full url https://example.com/some-page/
.
I would have thought the output would have been present or null, not partial.
It does work correctly in a non https environment.
Anyone have an idea if/how this can be fixed.
Upvotes: 1
Views: 1441
Reputation: 2901
It turned out to be my misunderstanding of the referrer policy "strict-origin". It is too restrictive on internal referrals. What I needed was the slightly less strict "same-origin".
You can see this excellent article which explains all.
Upvotes: 1