How to get Request.UrlReferrer and ServerVariables ["HTTP_REFERER"], which are NULL. Asp.Net

I have a simple page request form. When the user clicks the subscribe button, he comes to a page where I would like to receive information about where it came from. I checked it with a small site to make sure I have a redirect.

Request.UrlReferrer and ServerVariables ["HTTP_REFERER"] is NULL

IP and all other data in place.

How to find Url, Form was sent to my page?

A form designed to be embedded on any website / page with a simple copy / paste.

Thanks.

-one
source share
1 answer

Another SO user reported that HTTP_REFERER is not populated with messages in domains.

So, I think it would be better to rely on JavaScript to fill in the hidden input in your form with a link to the page before submitting. Something like that:

<form action="http://www.yourdomain.com/subscribe" method="POST" onsubmit= "document.getElementById('www.yourdomain.com.referrer').value=window.location;" > <!-- hidden input for field starts with a domain registered by you just so that it unlikely to clash with anything else on the page --> <input type="hidden" id="www.yourdomain.com.referrer" name="referrer"/> your email: <input name="email" type="text"/> ... rest of form ... <input type="submit" value="Subscribe"/> </form> 

You can then get the link URL from Request.Form ["referrer"] on the processing page.

0
source

All Articles