【问题标题】:How to get the page URL if the page request is made from a different URL?如果页面请求来自不同的 URL,如何获取页面 URL?
【发布时间】:2020-12-21 08:08:53
【问题描述】:

我正在开发一个 Web 应用程序,我遇到了一种情况,我需要知道用户是从哪个网站访问我的网站的。 我要找的是:

<a target="_blank" href="http://localhost:18835/index.aspx">To Web application</a>

在一个网站上说 StackOverflow 并且在该 index.aspx 页面加载时,我需要知道请求来自 StackOverflow 或任何其他网站,我需要知道发出页面请求的 URL。

我该怎么做?

string referencepage = HttpContext.Current.Request.UrlReferrer.AbsoluteUri;
label1.Text = "You Came from:-" + referencepage;

当请求是在当前 URL 内发出时,此代码将起作用,那么如果请求来自外部怎么办???

【问题讨论】:

标签: c# asp.net asp.net-core


【解决方案1】:
if (Request.ServerVariables["HTTP_REFERER"] != null)
{
    Response.Write(Request.ServerVariables["HTTP_REFERER"].ToString());
}

【讨论】:

    猜你喜欢
    • 2012-10-03
    • 1970-01-01
    • 1970-01-01
    • 2016-03-22
    • 1970-01-01
    • 1970-01-01
    • 2013-08-17
    • 1970-01-01
    • 2020-05-07
    相关资源
    最近更新 更多