Question

Okay my problem is there are two websites with two different servers. What I'm trying to do is write some of the buttons for website 1, but on a page on my server (website 2).

So to do this the approach is

  • User clicks on button from website 1.
  • User is redirected to website 2.
  • I need to know what page they came from so I know what product they are looking at. Which will be done by getting the referrer URL.
  • I then need to parse the URL's productID's number.

example URL: website1.com/ProductDetails/?referrerPage=1&productID=#######&tab=Tile

I know that I need to use this piece of code to store the referrer URL in a string:

myReferrer = Request.UrlReferrer.ToString();

I don't really know where to place it tho. I'm guessing in my .cs file where my button is?

protected void btnEstimate_Click(object sender, EventArgs e)
{
    connection strings
    {
        does stuff
        {
            does stuff
        }

So my question is how do I get the referring URL, and then parse out the item ID?

Thanks for the help in advance. If anything is unclear please ask... this is my first time asking a question so I may be unclear. Thanks!

Was it helpful?

Solution

This should give you what you want:

Making Sense of ASP.NET Paths

Note that a fully qualified URL including querystring and extra path is a Uri instance rather than string. You can use the UriBuilder.Query Property to extract the query string parameter(s):

You need to parse the URI in the Page_Load method of the receiving site's page.

UriBuilder.Query Property

OTHER TIPS

There's a server variable called HTTP_REFERER. You can access it with Request.ServerVariables("HTTP_REFERER")

It's misspelled, I know, but that's how you really need to call the server variable.

Your referrer server variable is only going to be populated if the user clicks on a link. AFAIK if you redirect, that variable is going to be empty.

Wikipedia Referer Article

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top