Asp.net get URL and IP address

Source: Internet
Author: User
Tags get ip

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

1. 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: 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;

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.