使用JavaScript和C#中獲得referer
1. JavaScript
/**
* 獲取HTTP請(qǐng)求的Referer
* @ishost 布爾類型 Referer為空時(shí)是否返回Host(網(wǎng)站首頁地址)
*/
function get_http_referer(ishost) {
if (ishost === undefined) { ishost = true; }
if (document.referrer) {
return document.referrer;
} else {
if (ishost) {
return window.location.protocol + "http://" + window.location.host;
} else {
return "";
}
}
}
2. C#
/// <summary>
/// 獲取HTTP請(qǐng)求的Referer
/// </summary>
/// <param name="ishost">Referer為空時(shí)是否返回Host(網(wǎng)站首頁地址)</param>
/// <returns>string</returns>
public string GetReferer(bool ishost)
{
if ( Request.UrlReferrer != null)
{
return Request.UrlReferrer.ToString();
}
else
{
if (ishost)
{
return Request.Url.Scheme + "://" + Request.Url.Authority;
}
else
{
return "";
}
}
}
3. C#中取得Request URL的各個(gè)部分
網(wǎng)址:http://localhost:1897/News/Press/Content.aspx/123?id=1#toc
Request.ApplicationPath /
Request.PhysicalPath D:\Projects\Solution\web\News\Press\Content.aspx
System.IO.Path.GetDirectoryName(Request.PhysicalPath) D:\Projects\Solution\web\News\Press
Request.PhysicalApplicationPath D:\Projects\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.AbsoluteUri http://localhost:1897/News/Press/Content.aspx/123?id=1
Request.Url.Scheme http
Request.Url.Host localhost
Request.Url.Port 1897
Request.Url.Authority localhost: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 /
News/
Press/
Content.aspx/
123
4. JavaScript window.location對(duì)象
http://www.dbjr.com.cn/article/57407.htm
怎么樣,是不是已經(jīng)學(xué)會(huì)了在javascript和C#中獲取頁面的referer了呢?如有什么疑問,也可以聯(lián)系我
相關(guān)文章
基于小程序請(qǐng)求接口wx.request封裝的類axios請(qǐng)求
這篇文章主要介紹了基于小程序請(qǐng)求接口wx.request封裝的類axios請(qǐng)求,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2020-07-07javascript ES6 Template String模板字符串使用方法
這篇文章主要介紹了javascript ES6 模板字符串(Template String)是增強(qiáng)版的字符串,用反引號(hào)(`)標(biāo)識(shí),它可以當(dāng)作普通字符串使用,也可以用來定義多行字符串,或者在字符串中嵌入變量,需要的朋友可以參考下2023-06-06JS+H5 Canvas實(shí)現(xiàn)時(shí)鐘效果
這篇文章主要為大家詳細(xì)介紹了JS+H5 Canvas實(shí)現(xiàn)時(shí)鐘效果,利用JavaScript和Canvas實(shí)現(xiàn)簡單時(shí)鐘效果,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2018-07-07JavaScript大數(shù)相加相乘的實(shí)現(xiàn)方法實(shí)例
這篇文章主要給大家介紹了關(guān)于JavaScript大數(shù)相加相乘的實(shí)現(xiàn)方法,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2020-10-10JS利用?clip-path?實(shí)現(xiàn)動(dòng)態(tài)區(qū)域裁剪功能
這篇文章主要介紹了JS利用?clip-path?實(shí)現(xiàn)動(dòng)態(tài)區(qū)域裁剪功能,文中主要通過使用 box-shadow 實(shí)現(xiàn),代碼簡單易懂,對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2021-12-12