最新国产好看的视频,伊人天堂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

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

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


正確的方法是:

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

HttpContext.Current.Request.Url.PathAndQuery

1、通過(guò)ASP.NET獲取
如果測(cè)試的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、通過(guò)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 = "沒(méi)有可用的連接";
}


myIP地址就是服務(wù)器端的ip地址。

獲取客戶(hù)端的ip地址,可以使用

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

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

2、通過(guò)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)頁(yè)圖片的具體方法

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

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

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

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

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

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

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

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

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

    這篇文章介紹了WPF框架Prism中使用MVVM架構(gòu)的方式,文中通過(guò)示例代碼介紹的非常詳細(xì)。對(duì)大家的學(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è)問(wèn)題,我們可以使用泛型集合 Dictionary(TKey,TValue)。它有一個(gè)key值用來(lái)存儲(chǔ)字符串和一個(gè)value值,用來(lái)存儲(chǔ)字符串出現(xiàn)的次數(shù)
    2012-05-05
  • ASP.NET MVC從視圖傳參到控制器的幾種形式

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

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

    ASP.NET Core中Grpc通信的簡(jiǎn)單用法

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

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

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

最新評(píng)論

云霄县| 辉县市| 遵义市| 启东市| 烟台市| 开远市| 南通市| 长顺县| 离岛区| 康定县| 诸暨市| 宁陵县| 易门县| 晋江市| 驻马店市| 滦南县| 辽阳县| 永新县| 南岸区| 伊川县| 佛冈县| 乐平市| 灵武市| 巧家县| 望都县| 商南县| 孝义市| 靖州| 永胜县| 昌图县| 昌邑市| 雅江县| 泽州县| 北流市| 长治市| 无为县| 广汉市| 阜新市| 依兰县| 浦县| 红桥区|