Source of request in asp.net/C#

Basically, I need to know the answer to this question in asp.net/C#:
source of REQUEST
I would like one of my pages to know which page directed the user to this specific page. I’ve tried going through intellisense on a few different Page properties, but couldn’t find it. Any help?

Answers:

Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

Sounds like your looking for Request.UrlReferrer

Documentation: HttpRequest.UrlReferrer

The request can be attained off the page:

Page.Request

If a Page instance is not available, you can get it from the current context using:

HttpContext.Current.Request

Method 2

You can look at Request.ServerVariables("HTTP_REFERER") or Request.ServerVariables("URL").

Or you can use the Request object this way:

Request.Url.ToString() gives you the full path of the calling page.

If you call this in the Immediate Window without the ToString, you can see lots of information:

Request.UrlReferrer.ToString()

Method 3

You’re looking for the Request.UrlReferrer property.

Method 4

I think you want Request.ServerVariables["HTTP_REFERER"];

EDIT:

Use @SLaks answer

Method 5

We can get to know the referral Url from UrlReferrer property.
It’s easy to handle in the global.asax file.

protected void Session_Start()
{
    var SourceURL = HttpContext.Current.Request.UrlReferrer.AbsoluteUri.ToString();
}

Now we can store this value in session or somewhere and do what ever operation we would like.


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x