Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

get parameters from referrer

Tags:

asp.net-mvc

Is there any easy way to extract the parameters of the referrer url as contained in Request.UrlReferrer? Is there another way to get the parameters used by the referrer?

Query?blahID=3&name=blah

I am refering to getting blahID and name from the url. It can be done with a bunch of string manipulations, but was hoping there was an easier way.

like image 767
BobTurbo Avatar asked Jul 15 '11 13:07

BobTurbo


People also ask

What is referrer parameter?

Referrer parameters refer to where the person was previously and you can pull data into the form there too. The URL paramater is purely about the current page, and the referring paramater is about the previous page.

How do I get referrer in Java?

It's available in the HTTP referer header. You can get it in a servlet as follows: String referrer = request. getHeader("referer"); // Yes, with the legendary misspelling.

What is ref in a URL?

The address of the webpage where a person clicked a link that sent them to your page. The referrer is the webpage that sends visitors to your site using a link.


1 Answers

Use HttpUtility.ParseQueryString from System.Web. Something like this should work:

string blahID = string.Empty;
if(Request.UrlReferrer != null)
{
    var q = HttpUtility.ParseQueryString(Request.UrlReferrer.Query);
    blahID = q["blahID"];
}
like image 120
rsbarro Avatar answered Sep 20 '22 18:09

rsbarro