熱點推薦:
您现在的位置: 電腦知識網 >> 編程 >> .NET編程 >> 正文

asp.net獲取URL和IP地址

2022-06-13   來源: .NET編程 

  獲取URL:

  通過ASPNET獲取如果測試的url地址是x 結果如下

  RequestApplicationPath: /testweb RequestCurrentExecutionFilePath: /testweb/defaultaspx RequestFilePath: /testweb/defaultaspx RequestPath: /testweb/defaultaspx RequestPhysicalApplicationPath: E:\WWW\testweb\ RequestPhysicalPath: E:\WWW\testweb\defaultaspx RequestRawUrl: /testweb/defaultaspx RequestUrlAbsolutePath: /testweb/defaultaspx RequestUrlAbsoluteUrl: x RequestUrlHost: RequestUrlLocalPath: /testweb/defaultaspx

  通過JS獲取

  <table width=% cellpadding= cellspacing= border= >

  <script>

  thisURL = documentURL;

  thisHREF = documentlocationhref;

  thisSLoc = selflocationhref;

  thisDLoc = documentlocation;

  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>

  documentwrite( strwrite );

  </script>

  thisDLoc = documentlocation; <BR>

  thisURL = documentURL; <BR>

  thisHREF = documentlocationhref; <BR>

  thisSLoc = selflocationhref;<BR>

  <script>

  thisTLoc = toplocationhref;

  thisPLoc = parentdocumentlocation;

  thisTHost = toplocationhostname;

  thisHost = locationhostname;

  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>

  documentwrite( strwrite );

  </script>

  thisTLoc = toplocationhref; <BR>

  thisPLoc = parentdocumentlocation; <BR>

  thisTHost = toplocationhostname; <BR>

  thisHost = locationhostname;<BR>

  <script>

  tmpHPage = thisHREFsplit( / );

  thisHPage = tmpHPage[ tmpHPagelength ];

  tmpUPage = thisURLsplit( / );

  thisUPage = tmpUPage[ tmpUPagelength ];

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

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

  documentwrite( strwrite );

  </script><tr><td>

  獲取IP

  ASPNET中獲取

  獲取服務器的IP地址

  using SystemNet;

  string myIPmyMac;

  SystemNetIPAddress[] addressList = DnsGetHostByName(DnsGetHostName())AddressList;

  if ( addressListLength>)

  {

  myIP = addressList[]ToString();

  myMac = addressList[]ToString();

  }

  else

  {

  myIP = addressList[]ToString();

  myMac = 沒有可用的連接

  }

  myIP地址就是服務器端的ip地址

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

  //獲取登錄者ip地址

  string ip = RequestServerVariables[REMOTE_ADDR]ToString();

  通過JS獲取

  <html>

  <head>

  <title></title>

  <meta httpequiv=ContentType content=text/html; charset=gbk>

  </head>

  <body>

  <object classid=CLSID:ACBDBDB id=locator ></object>

  <object classid=CLSID:CAFdAACCFBC id=foo ></object>

  <form name=myForm>

  <br>MAC地址<input type=text name=macAddress>

  <br>IP地址<input type=text name=ipAddress>

  <br>主機名<input type=text name=hostName>

  </form>

  </body>

  </html>

  <script language=javascript>

  var sMacAddr=;

  var sIPAddr=;

  var sDNSName=;

  var service = locatorConnectServer();

  serviceSecurity_ImpersonationLevel=;

  serviceInstancesOfAsync(foo Win_NetworkAdapterConfiguration);

  </script>

  <script FOR=foo EVENT=OnObjectReady(objObjectobjAsyncContext) LANGUAGE=JScript> if(objObjectIPEnabled != null && objObjectIPEnabled != undefined && objObjectIPEnabled == true){ if(objObjectIPEnabled && objObjectIPAddress() !=null && objObjectIPAddress() != undefined) sIPAddr = objObjectIPAddress();

  if(objObjectMACAddress != null &&objObjectMACAddress != undefined) sMacAddr = objObjectMACAddress;

  if(objObjectDNSHostName != null &&objObjectDNSHostName != undefined) sDNSName = objObjectDNSHostName;

  }

  </script>

  <script FOR=foo EVENT=OnCompleted(hResultpErrorObject pAsyncContext) LANGUAGE=JScript>

  myFormmacAddressvalue=sMacAddr;

  myFormipAddressvalue=sIPAddr;

  myFormhostNamevalue=sDNSName;

  </script>


From:http://tw.wingwit.com/Article/program/net/201311/12829.html
    推薦文章
    Copyright © 2005-2022 電腦知識網 Computer Knowledge   All rights reserved.