0

I'm going off this: How do I get the referrer URL in an ASP.NET MVC action?

It works. I am recieving a URL when my form is submitted, but it's the same URL the contact form is on. I'm guessing when I hit submit, it thinks the previous page is the contact page. I'd like to find out the page the user was on BEFORE the contact form page.

This is what I have:

sb.Append("<p>Referrer URL: " + Request.ServerVariables["HTTP_REFERER"] + "</p>");
Community
  • 1
  • 1

1 Answers1

2

You could store the Referer in a hidden field in the form:

<input type="hidden" name="referer" value="<%=Request.ServerVariables["HTTP_REFERER"] %>" />
Sebastian Brand
  • 547
  • 4
  • 10
  • it sent the actual string "<%=Request.ServerVariables["HTTP_REFERER"] %>". Is that because I'm using Razor/C#? – Christopher Northcutt Apr 13 '16 at 19:41
  • @ChristopherNorthcutt To convert this to something like your original example, it would be: `sb.Append("");` – Jack A. Apr 13 '16 at 20:02
  • @JackA. I just want to send the text of the URL though not the entire input form. Right now I have this in the controller: sb.Append("

    Referrer URL: " + Request["referer"] + "

    "); and this in the .cshtml file:
    – Christopher Northcutt Apr 13 '16 at 20:14