Nick Rolando
Nick Rolando

Reputation: 26157

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?

Upvotes: 7

Views: 11186

Answers (5)

Venugopal M
Venugopal M

Reputation: 2412

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.

Upvotes: 0

Tom B
Tom B

Reputation: 2180

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

EDIT:

Use @SLaks answer

Upvotes: 0

SLaks
SLaks

Reputation: 887215

You're looking for the Request.UrlReferrer property.

Upvotes: 3

DOK
DOK

Reputation: 32831

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()

Upvotes: 3

cweston
cweston

Reputation: 11637

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

Upvotes: 14

Related Questions