1。JavaScript
コードコピーは次のとおりです。
/**
* HTTPリクエストの参照を取得します
* @ishostブール参照が空のときにホストを返すかどうか(ホームページのアドレス)
*/
関数get_http_referer(ishost){
if(ishost === undefined){ishost = true; }
if(document.referrer){
document.referrerを返します。
} それ以外 {
if(ishost){
window.location.protocol + "//" + window.location.host;
} それ以外 {
戻る "";
}
}
}
2。C#
コードコピーは次のとおりです。
/// <summary>
/// HTTPリクエスト参照を取得します
/// </summary>
/// <param name = "ishost">参照が空のときにホストを返すかどうか(ホームページのアドレス)</param>
/// <returns> string </returns>
パブリックストリングgetReferer(bool ishost)
{
if(request.urlreferrer!= null)
{
return request.urlreferrer.toString();
}
それ以外
{
if(ishost)
{
return request.url.scheme + "://" + request.url.authority;
}
それ以外
{
戻る "";
}
}
}
3。c#でリクエストURLのさまざまな部分を取得します
ウェブサイト:http:// localhost:1897/news/press/content.aspx/123?id = 1#toc
コードコピーは次のとおりです。
request.ApplicationPath/
request.physicalpathd:/projects/solution/web/news/press/content.aspx
system.io.path.getDirectoryName(request.physicalpath)d:/projects/solution/web/news/press
request.physicalapplicationpathd:/project/solution/web/
System.io.Path.GetFileName(Request.PhysicalPath)content.aspx
request.currentexecutionfilepath/news/press/content.aspx
request.filepath/news/press/content.aspx
request.path/news/press/content.aspx/123
request.rawurl/news/press/content.aspx/123?id = 1
request.url.absolutepath/news/press/content.aspx/123
request.url.absoluteurihttp:// localhost:1897/news/press/content.aspx/123?id = 1
request.url.schemehttp
request.url.hostlocalhost
request.url.port1897
request.url.authoritylocalhost:1897
request.url.localpath/news/press/content.aspx/123
request.pathinfo/123
request.url.pathandquery/news/press/content.aspx/123?id = 1
request.url.query?id = 1
request.url.fragment
request.url.segments/
ニュース/
プレス/
content.aspx/
123
4。JavaScriptウィンドウ。Locationオブジェクト
//www.vevb.com/article/57407.htm
それはどうですか? JavaScriptとC#のページの参照者を取得することを学びましたか?ご質問がある場合は、ご連絡ください。