This section describes how to obtain the complete URL of the current page by ASP. NET. icech makes it a function. Use it directly!
Private string GetPath ()
{
String strPath = "http: //" + Request. ServerVariables ["HTTP_HOST"] + Request. ServerVariables ["PATH_INFO"] + "? "+ Request. ServerVariables [" QUERY_STRING "];
If (strPath. EndsWith ("? "))
{
StrPath = strPath. Substring (0, strPath. Length-1 );
}
Return strPath;
}
----------------------------------------------
Asp.net get URL and IP address
HttpContext. Current. Request. Url. ToString () is not reliable.
If the current URL is
Http: // localhost/search. aspx? User = http://csharp.xdowns.com & tag = % BC % CA % F5
Obtained Through HttpContext. Current. Request. Url. ToString () is
Http: // localhost/search. aspxuser = http://csharp.xdowns.com & tag = & frac14; & frac14; & Ecirc; & otilde;
The correct method is: HttpContext. Current. Request. Url. PathAndQuery1, obtained through ASP. NET
If the url for the test is a http://www.test.com/testweb/default.aspx, the results are as follows:
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: http://www.test.com/
Request. Url. LocalPath:/testweb/default. aspx
2. Get it through 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.doc ument. 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.doc ument. 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>
========================
Get IP
1. obtained in ASP. NET
Get the Server IP Address:
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 = "no available connections ";
}
The myIP address is the IP address of the server.
Obtain the IP address of the client.
// Obtain the publisher's IP address
String ip = Request. ServerVariables ["REMOTE_ADDR"]. ToString ();
2. Get it through JS
<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 address: <input type = "text" name = "macAddress">
<Br/> ip address: <input type = "text" name = "ipAddress">
<Br/> Host name: <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>
This article from the CSDN blog, reproduced please indicate the source: http://blog.csdn.net/david_520042/archive/2009/06/04/4241853.aspx
This section describes how to obtain the complete URL of the current page by ASP. NET. icech makes it a function. Use it directly!
Private string GetPath ()
{
String strPath = "http: //" + Request. ServerVariables ["HTTP_HOST"] + Request. ServerVariables ["PATH_INFO"] + "? "+ Request. ServerVariables [" QUERY_STRING "];
If (strPath. EndsWith ("? "))
{
StrPath = strPath. Substring (0, strPath. Length-1 );
}
Return strPath;
}
----------------------------------------------
Asp.net get URL and IP address
HttpContext. Current. Request. Url. ToString () is not reliable.
If the current URL is
Http: // localhost/search. aspx? User = http://csharp.xdowns.com & tag = % BC % CA % F5
Obtained Through HttpContext. Current. Request. Url. ToString () is
Http: // localhost/search. aspxuser = http://csharp.xdowns.com & tag = & frac14; & frac14; & Ecirc; & otilde;
The correct method is: HttpContext. Current. Request. Url. PathAndQuery1, obtained through ASP. NET
If the url for the test is a http://www.test.com/testweb/default.aspx, the results are as follows:
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: http://www.test.com/
Request. Url. LocalPath:/testweb/default. aspx
2. Get it through 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.doc ument. 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.doc ument. 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>
========================
Get IP
1. obtained in ASP. NET
Get the Server IP Address:
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 = "no available connections ";
}
The myIP address is the IP address of the server.
Obtain the IP address of the client.
// Obtain the publisher's IP address
String ip = Request. ServerVariables ["REMOTE_ADDR"]. ToString ();
2. Get it through JS
<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 address: <input type = "text" name = "macAddress">
<Br/> ip address: <input type = "text" name = "ipAddress">
<Br/> Host name: <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>
This article from the CSDN blog, reproduced please indicate the source: http://blog.csdn.net/david_520042/archive/2009/06/04/4241853.aspx