国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > .NET > 正文

asp.net獲取URL和IP地址的方法匯總

2024-07-10 12:46:10
字體:
來源:轉載
供稿:網友

HttpContext.Current.Request.Url.ToString() 并不可靠。

如果當前URL為
http://localhost/search.aspx?user=http://csharp.xdowns.com&tag=%BC%BC%CA%F5

通過HttpContext.Current.Request.Url.ToString()獲取到的卻是

http://localhost/search.aspxuser=http://csharp.xdowns.com&tag=¼¼Êõ


正確的方法是:

代碼如下:
HttpContext.Current.Request.Url.PathAndQuery

1、通過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.aspx

2、通過JS獲取
代碼如下:
<table width=100% cellpadding=0 cellspacing=0 border=0 >

<script>

thisURL = document.URL;

thisHREF = document.location.href;

thisSLoc = self.location.href;

thisDLoc = document.location;

strwrite = "<tr><td valign=top>thisURL: </td><td>[" + thisURL + "]</td></tr>"

strwrite += "<tr><td valign=top>thisHREF: </td><td>[" + thisHREF + "]</td></tr>"

strwrite += "<tr><td valign=top>thisSLoc: </td><td>[" + thisSLoc + "]</td></tr>"

strwrite += "<tr><td valign=top>thisDLoc: </td><td>[" + thisDLoc + "]</td></tr>"

document.write( strwrite );

</script>

thisDLoc = document.location; <BR>

thisURL = document.URL; <BR>

thisHREF = document.location.href; <BR>

thisSLoc = self.location.href;<BR>

<script>

thisTLoc = top.location.href;

thisPLoc = parent.document.location;

thisTHost = top.location.hostname;

thisHost = location.hostname;

strwrite = "<tr><td valign=top>thisTLoc: </td><td>[" + thisTLoc + "]</td></tr>"

strwrite += "<tr><td valign=top>thisPLoc: </td><td>[" + thisPLoc + "]</td></tr>"

strwrite += "<tr><td valign=top>thisTHost: </td><td>[" + thisTHost + "]</td></tr>"

strwrite += "<tr><td valign=top>thisHost: </td><td>[" + thisHost + "]</td></tr>"

document.write( strwrite );

</script>

thisTLoc = top.location.href; <BR>

thisPLoc = parent.document.location; <BR>

thisTHost = top.location.hostname; <BR>

thisHost = location.hostname;<BR>

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 嘉兴市| 青川县| 兰考县| 遂平县| 那曲县| 桂平市| 内黄县| 汨罗市| 襄樊市| 万宁市| 萨嘎县| 广德县| 大厂| 林甸县| 黄冈市| 华宁县| 博客| 甘谷县| 黑水县| 永兴县| 绵阳市| 秀山| 缙云县| 海口市| 新闻| 南雄市| 墨玉县| 手机| 肇源县| 淮北市| 嵊州市| 通河县| 祁门县| 潮州市| 湘潭县| 宣城市| 湖北省| 临桂县| 彝良县| 和田市| 嘉峪关市|