Source of request in asp.net/C#

2020-04-04 05:12发布

问题:

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?

回答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


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


回答3:

You're looking for the Request.UrlReferrer property.



回答4:

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

EDIT:

Use @SLaks answer



回答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.



标签: c# asp.net