1. JavaScript
Salinan kode adalah sebagai berikut:
/**
* Dapatkan referer permintaan http
* @ishost Apakah akan mengembalikan host ketika referer boolean kosong (alamat beranda)
*/
fungsi get_http_referer (ishost) {
if (ishost === tidak terdefinisi) {ishost = true; }
if (document.referrer) {
return document.referrer;
} kalau tidak {
if (iShost) {
return window.location.protocol + "//" + window.location.host;
} kalau tidak {
kembali "";
}
}
}
2. C#
Salinan kode adalah sebagai berikut:
/// <summary>
/// Dapatkan referer permintaan http
/// </summary>
/// <param name = "ishost"> apakah akan mengembalikan host saat referer kosong (alamat beranda) </param>
/// <Returns> string </eturns>
string publik getReferer (bool ishost)
{
if (request.urlreferrer! = null)
{
return request.urlreferrer.tostring ();
}
kalau tidak
{
if (ishost)
{
return request.url.scheme + ": //" + request.url.authority;
}
kalau tidak
{
kembali "";
}
}
}
3. Dapatkan berbagai bagian URL permintaan di C#
Situs web: http: // localhost: 1897/news/press/content.aspx/123? Id = 1#toc
Salinan kode adalah sebagai berikut:
Request.ApplicationPath/
Request.physicalpathd: /projects/solution/web/news/press/content.aspx
System.io.path.getDirectoryName (request.physicalPath) D:/Proyek/Solusi/Web/Berita/Pers
Request.physicalApplicationPathd:/Project/Solution/Web/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/
Berita/
Tekan/
Content.aspx/
123
4. JavaScript Window. Objek Lokasi
//www.vevb.com/article/57407.htm
Bagaimana dengan itu? Pernahkah Anda belajar mendapatkan referer halaman di JavaScript dan C#? Jika Anda memiliki pertanyaan, silakan hubungi saya.