0

How to retrieve the url of request without using Request.UrlReferrer in mvc c#? I read that Request.UrlReferrer is not reliable. What is best way to achieve it?

ramires.cabral
  • 910
  • 4
  • 13
  • 28
  • I have had no issues using Requset.UriReferrer perhaps you are using it wrong.. have your tired the following `var someUrl = HttpContext.Current.Request.UrlReferrer.AbsoluteUri` – MethodMan Mar 09 '15 at 18:29
  • Request.Url.PathAndQuery ? – krilovich Mar 09 '15 at 18:39
  • 1
    According to MSDN propper way is to use the URLReferrer - https://msdn.microsoft.com/en-us/library/system.web.httprequest.urlreferrer(v=vs.110).aspx If you are able to use client side- Javascript allows you to get it by using var x = document.referrer; – Dashsa Mar 09 '15 at 18:39
  • @ramires Would you please share the link to the source that says that `Request.UrlReferrer` is not reliable? – Quality Catalyst Mar 09 '15 at 18:59
  • http://stackoverflow.com/questions/4258217/getting-the-http-referrer-in-asp-net. The answer of Darin Dimitrov is one example. Among others I read. – ramires.cabral Mar 09 '15 at 19:03
  • I personally don't like to use it, and I don't like when my business depends knowing what was the previous page! but apparently sometimes you have to it. One other approach you can use (but only if request is from your own website) is query string, this is usually used when user goes to login so that login pages figures out where to send the user after he is authenticated. – A Khudairy Mar 10 '15 at 08:22

1 Answers1

0

I think what it means is that the referrer header itself is not reliable because it's entirely in the power of the users' browser whether it will be sent over to the server or not.

As @Dashsa in the comments suggested you need to create a javascript solution. But that will obviously not work for requests coming from outside your application.

Vilém Procházka
  • 1,060
  • 2
  • 17
  • 28