Experience the new. Net Ajax brushless Technology

Source: Internet
Author: User
1. Create a new project and add reference Ajax. DLL to the reference. Ajax. dll is located in the downloaded package.

   2. Create httphandler and add it to Web. config.<configuration>
<system.web>
<httpHandlers>
<add verb="POST,GET" path="ajax/*.ashx" type="Ajax.PageHandlerFactory, Ajax" />
</httpHandlers>
...
<system.web>
</configuration>
3. Create a new class demomethods, which can obtain the client MAC address:using System;
using System.Web;
namespace AjaxSample
{
///

/// Summary description for Methods.
///

public class DemoMethods
{

[Ajax.AjaxMethod]
public string GetCustomerMac(string clientIP) //para IP is the client's IP
{
string mac = "";
System.Diagnostics.Process process = new System.Diagnostics.Process();
process.StartInfo.FileName = "nbtstat";
process.StartInfo.Arguments = "-a "+clientIP;
process.StartInfo.UseShellExecute = false;
process.StartInfo.CreateNoWindow = true;
process.StartInfo.RedirectStandardOutput = true;

process.Start();

string output = process.StandardOutput.ReadToEnd();
int length = output.IndexOf("MAC Address = ");
if(length> 0)
{
mac = output.Substring(length+14, 17);
}

process.WaitForExit();

return mac.Replace("-", "").Trim();
}
}
}

4. Write JavaScript and create a new file named default. The JS file is as follows:

function GetMac()
{
var clientIP="192.168.0.1";
document.getElementById("Mac").value=DemoMethods.GetCustomerMac(clientIP).value
alert(DemoMethods.GetCustomerMac(clientIP).value);
}

5. Put an HTML button on An ASPX page

Reference default. js on the page:

Add onclick = "javascript: getmac ()" to the onclick event of input ()"

Value = "Client IP" onclick = "javascript: getmac ();">

   6. Modify the application_start event of Global. asax and set the Ajax handlerpath:

Protected void application_start (Object sender, eventargs E)
{
Ajax. Utility. handlerpath = "ajax ";
}

Note that the. NET Ajax version must be manually added with Ajax. Utility. handlerpath = "ajax" in global. asax. The httphandler configuration information must be added to the web. config configuration file!

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.