HttpContext.Current.Request.Url.ToString() 並不可靠。web
若是當前URL爲
http://localhost/search.aspx?user=http://csharp.xdowns.com&tag=%BC%BC%CA%F5服務器
經過HttpContext.Current.Request.Url.ToString()獲取到的倒是app
http://localhost/search.aspxuser=http://csharp.xdowns.com&tag=¼¼Êõ;測試
正確的方法是:HttpContext.Current.Request.Url.PathAndQuery一、經過ASP.NET獲取
若是測試的url地址是http://www.test.com/testweb/default.aspx, 結果以下:
Request.ApplicationPath: /testweb
Request.CurrentExecutionFilePath: /testweb/default.aspx
Request.FilePath: /testweb/default.aspx
Request.Path: /testweb/default.aspx
Request.PhysicalApplicationPath: E:\WWW\testwebRequest.PhysicalPath: E:\WWW\testweb\default.aspx
Request.RawUrl: /testweb/default.aspx
Request.Url.AbsolutePath: /testweb/default.aspx
Request.Url.AbsoluteUrl: http://www.test.com/testweb/default.aspx
Request.Url.Host: www.test.com
Request.Url.LocalPath: /testweb/default.aspxthis
二、經過JS獲取url
thisDLoc = document.location;
spa
thisURL = document.URL;
ip
thisHREF = document.location.href;
ci
thisSLoc = self.location.href;
string
thisTLoc = top.location.href;
thisPLoc = parent.document.location;
thisTHost = top.location.hostname;
thisHost = location.hostname;
================= 獲取IP 一、ASP.NET中獲取 獲取服務器的IP地址: using System.Net; string myIP,myMac; System.Net.IPAddress[] addressList = Dns.GetHostByName(Dns.GetHostName()).AddressList; if ( addressList.Length>1) { myIP = addressList[0].ToString(); myMac = addressList[1].ToString(); } else { myIP = addressList[0].ToString(); myMac = "沒有可用的鏈接"; } myIP地址就是服務器端的ip地址。 獲取客戶端的ip地址,能夠使用 //獲取登陸者ip地址string ip = Request.ServerVariables["REMOTE_ADDR"].ToString(); 二、經過JS獲取 |