獲取Url的方法有兩種,通過後臺獲得或通過前面js獲得,如下:
1、通過C#獲取當前頁面的URL
string host = Request.Url.Host; //結果:www.codes51.com
string localPath = Request.Url.LocalPath; //結果:/web/index.aspx
2、通過Javascript獲取當前頁面的URL
var href = document.location.href; //結果:http://www.codes51.com/web/index.aspx
var host = location.hostname; //結果:www.codes51.com