开发者

Source of request in asp.net/C#

开发者 https://www.devze.com 2023-02-08 04:17 出处:网络
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 throug

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 pro开发者_运维百科perties, 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


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


You're looking for the Request.UrlReferrer property.


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

EDIT:

Use @SLaks answer


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消