简体   繁体   中英

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?

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

您正在寻找Request.UrlReferrer属性

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

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.

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

EDIT:

Use @SLaks answer

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM