獲取當(dāng)前url
更新時間:2006年08月24日 00:00:00 作者:
如:http://localhost/newurl/WebForm1.aspx
1.方法document.URL(注意大小寫)
結(jié)果是:http://localhost/newurl/WebForm1.aspx
2.HttpContext.Current.Request.Url.ToString(),
結(jié)果:http://localhost/newurl/WebForm1.aspx
3.HttpContext.Current.Request.Url.PathAndQuery;
結(jié)果:/newurl/WebForm1.aspx
備注:
如果當(dāng)前URL為
http://localhost/search.aspx?user=tinyfool&tag=%BC%BC%CA%F5
通過HttpContext.Current.Request.Url.ToString()獲取到的卻是
http://localhost/search.aspx?user=tinyfool&tag=¼¼Êõ
這顯然不對,怎么辦?用HttpContext.Current.Request.Url.PathAndQuery好了,這個得到的正確的。:)
4.Javascript取url值
剛寫的一個小實例.實際中使用還是蠻多的.
[Ctrl+A 全選 注:引入外部Js需再刷新一下頁面才能執(zhí)行]
1.方法document.URL(注意大小寫)
結(jié)果是:http://localhost/newurl/WebForm1.aspx
2.HttpContext.Current.Request.Url.ToString(),
結(jié)果:http://localhost/newurl/WebForm1.aspx
3.HttpContext.Current.Request.Url.PathAndQuery;
結(jié)果:/newurl/WebForm1.aspx
備注:
如果當(dāng)前URL為
http://localhost/search.aspx?user=tinyfool&tag=%BC%BC%CA%F5
通過HttpContext.Current.Request.Url.ToString()獲取到的卻是
http://localhost/search.aspx?user=tinyfool&tag=¼¼Êõ
這顯然不對,怎么辦?用HttpContext.Current.Request.Url.PathAndQuery好了,這個得到的正確的。:)
4.Javascript取url值
剛寫的一個小實例.實際中使用還是蠻多的.
[Ctrl+A 全選 注:引入外部Js需再刷新一下頁面才能執(zhí)行]
相關(guān)文章
ASP.NET MVC中_ViewStart.cshtml作用介紹
這篇文章介紹了ASP.NET MVC中_ViewStart.cshtml的作用,對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2022-03-03
.Net行為型設(shè)計模式之狀態(tài)模式(State)
這篇文章介紹了.Net行為型設(shè)計模式之狀態(tài)模式(State),文中通過示例代碼介紹的非常詳細。對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友可以參考下2022-05-05
.net?6精簡版webapi教程及熱重載、代碼自動反編譯演示
這篇文章介紹了.net?6精簡版webapi教程及熱重載、代碼自動反編譯演示,對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2021-12-12

