獲取Url的方法有兩種,通過后臺獲得或通過前面js獲得,如下:
1、通過C#獲取當前頁面的URL
string url = Request.Url.AbsoluteUri; //結果: http://www.companysz.com/web/index.aspx
string host = Request.Url.Host; //結果:www.companysz.com
string rawUrl = Request.RawUrl; //結果:/web/index.aspx
string localPath = Request.Url.LocalPath; //結果:/web/index.aspx
2、通過Javascript獲取當前頁面的URL
var url = document.URL; //結果:http://www.companysz.com/web/index.aspx
var href = document.location.href; //結果:http://www.companysz.com/web/index.aspx
var host = location.hostname; //結果:www.companysz.com
以上就是小編為大家帶來的在asp.net中獲取當前頁面的URL的方法(推薦)的全部內容了,希望對大家有所幫助,多多支持VeVb武林網~
新聞熱點
疑難解答
圖片精選