最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

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

 更新時(shí)間:2013年03月19日 09:19:20   作者:  
asp.net獲取URL和IP地址的方法匯總,需要的朋友可以參考一下

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

如果當(dāng)前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=¼¼Êõ


正確的方法是:

復(fù)制代碼 代碼如下:

HttpContext.Current.Request.Url.PathAndQuery

1、通過ASP.NET獲取
如果測試的url地址是http://www.test.com/testweb/default.aspx, 結(jié)果如下:
復(fù)制代碼 代碼如下:

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獲取
復(fù)制代碼 代碼如下:

<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>

<script>

tmpHPage = thisHREF.split( "/" );

thisHPage = tmpHPage[ tmpHPage.length-1 ];

tmpUPage = thisURL.split( "/" );

thisUPage = tmpUPage[ tmpUPage.length-1 ];

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

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

document.write( strwrite );

</script><tr><td>


=================
獲取IP
1、ASP.NET中獲取

獲取服務(wù)器的IP地址:

復(fù)制代碼 代碼如下:

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地址就是服務(wù)器端的ip地址。

獲取客戶端的ip地址,可以使用

復(fù)制代碼 代碼如下:

//獲取登錄者ip地址
string ip = Request.ServerVariables["REMOTE_ADDR"].ToString();

2、通過JS獲取
復(fù)制代碼 代碼如下:

<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=gbk">
</head>

<body>

<object classid="CLSID:76A64158-CB41-11D1-8B02-00600806D9B6" id="locator" style="display:none;visibility:hidden"></object>
<object classid="CLSID:75718C9A-F029-11d1-A1AC-00C04FB6C223" id="foo" style="display:none;visibility:hidden"></object>

<form name="myForm">
<br/>MAC地址:<input type="text" name="macAddress">
<br/>IP地址:<input type="text" name="ipAddress">
<br/>主機(jī)名:<input type="text" name="hostName">
</form>

</body>
</html>
<script language="javascript">
var sMacAddr="";
var sIPAddr="";
var sDNSName="";

var service = locator.ConnectServer();
service.Security_.ImpersonationLevel=3;
service.InstancesOfAsync(foo, 'Win32_NetworkAdapterConfiguration');

</script>

<script FOR="foo" EVENT="OnObjectReady(objObject,objAsyncContext)" LANGUAGE="JScript">
if(objObject.IPEnabled != null && objObject.IPEnabled != "undefined" && objObject.IPEnabled == true){
if(objObject.IPEnabled && objObject.IPAddress(0) !=null && objObject.IPAddress(0) != "undefined")
sIPAddr = objObject.IPAddress(0);
if(objObject.MACAddress != null &&objObject.MACAddress != "undefined")
sMacAddr = objObject.MACAddress;
if(objObject.DNSHostName != null &&objObject.DNSHostName != "undefined")
sDNSName = objObject.DNSHostName;
}
</script>

<script FOR="foo" EVENT="OnCompleted(hResult,pErrorObject, pAsyncContext)" LANGUAGE="JScript">

myForm.macAddress.value=sMacAddr;
myForm.ipAddress.value=sIPAddr;
myForm.hostName.value=sDNSName;
</script>

相關(guān)文章

  • asp.net采集網(wǎng)頁圖片的具體方法

    asp.net采集網(wǎng)頁圖片的具體方法

    采集網(wǎng)頁上圖片的主要關(guān)鍵是在怎么解析出頁面代碼里那些img標(biāo)簽的src屬性
    2013-06-06
  • ASP.NET中使用Application對象實(shí)現(xiàn)簡單在線人數(shù)統(tǒng)計(jì)功能

    ASP.NET中使用Application對象實(shí)現(xiàn)簡單在線人數(shù)統(tǒng)計(jì)功能

    這篇文章主要介紹了ASP.NET中使用Application對象實(shí)現(xiàn)簡單在線人數(shù)統(tǒng)計(jì)功能,本文給出實(shí)現(xiàn)步驟和相應(yīng)代碼實(shí)例,需要的朋友可以參考下
    2015-06-06
  • AspNetPager+GridView實(shí)現(xiàn)分頁的實(shí)例代碼

    AspNetPager+GridView實(shí)現(xiàn)分頁的實(shí)例代碼

    AspNetPager+GridView實(shí)現(xiàn)分頁的實(shí)例代碼,需要的朋友可以參考一下
    2013-03-03
  • asp.net獲取網(wǎng)站絕對路徑示例

    asp.net獲取網(wǎng)站絕對路徑示例

    在編寫 ASP.NET 應(yīng)用程序的時(shí)候,有時(shí)為了更好地進(jìn)行控制靜態(tài)文件的路徑,如在模板頁或者用戶控件中設(shè)置js或者css文件的路徑等,采用絕對路徑是難免的。下面就是幾種獲取絕對路徑的幾種方法
    2014-02-02
  • WPF框架Prism中使用MVVM架構(gòu)

    WPF框架Prism中使用MVVM架構(gòu)

    這篇文章介紹了WPF框架Prism中使用MVVM架構(gòu)的方式,文中通過示例代碼介紹的非常詳細(xì)。對大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2022-02-02
  • .net msmq消息隊(duì)列實(shí)例詳解

    .net msmq消息隊(duì)列實(shí)例詳解

    這篇文章主要為大家詳細(xì)介紹了.net msmq消息隊(duì)列的實(shí)例,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2018-04-04
  • asp.net 計(jì)算字符串中各個(gè)字符串出現(xiàn)的次數(shù)

    asp.net 計(jì)算字符串中各個(gè)字符串出現(xiàn)的次數(shù)

    比如一個(gè)字符串"a,b,a,c,b,b,d",現(xiàn)在我們要統(tǒng)計(jì)每個(gè)字符串出現(xiàn)次數(shù)。解決這個(gè)問題,我們可以使用泛型集合 Dictionary(TKey,TValue)。它有一個(gè)key值用來存儲字符串和一個(gè)value值,用來存儲字符串出現(xiàn)的次數(shù)
    2012-05-05
  • ASP.NET MVC從視圖傳參到控制器的幾種形式

    ASP.NET MVC從視圖傳參到控制器的幾種形式

    這篇文章主要介紹了ASP.NET MVC從視圖傳參到控制器的幾種形式,非常不錯(cuò),具有參考借鑒價(jià)值,需要的朋友可以參考下
    2017-04-04
  • ASP.NET Core中Grpc通信的簡單用法

    ASP.NET Core中Grpc通信的簡單用法

    這篇文章介紹了ASP.NET Core中Grpc通信的簡單用法,文中通過示例代碼介紹的非常詳細(xì)。對大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2022-07-07
  • ASP.NET Core 3.0遷移的完美避坑指南

    ASP.NET Core 3.0遷移的完美避坑指南

    這篇文章主要給大家介紹了關(guān)于ASP.NET Core 3.0遷移的完美避坑指南,文中通過示例代碼介紹的非常詳細(xì),對大家學(xué)習(xí)或者使用ASP.NET Core 3.0具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面來一起學(xué)習(xí)學(xué)習(xí)吧
    2019-09-09

最新評論

两当县| 三穗县| 通江县| 抚远县| 彰武县| 衡东县| 平罗县| 伊川县| 阳城县| 大埔县| 体育| 怀宁县| 肥西县| 新河县| 文成县| 荔波县| 图木舒克市| 潞城市| 荔波县| 湘潭市| 石嘴山市| 本溪市| 镇宁| 保山市| 渭南市| 兰考县| 凤城市| 青川县| 阜康市| 平山县| 长春市| 丘北县| 舒兰市| 镇沅| 子洲县| 梓潼县| 兴城市| 眉山市| 平遥县| 泗水县| 玛纳斯县|