簡體   English   中英

如果頁面請求來自不同的 URL,如何獲取頁面 URL?

[英]How to get the page URL if the page request is made from a different URL?

我正在開發一個 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 內發出時,此代碼將起作用,那么如果請求來自外部呢?

if (Request.ServerVariables["HTTP_REFERER"] != null)
{
    Response.Write(Request.ServerVariables["HTTP_REFERER"].ToString());
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM