Today, I got a. net Ajax development kit, which includes ASP2.0 and Ajax currently used in ASP1.1. For more information, see http://ajax.schwarz-interactive.de.
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>
/// Summary description for Methods.
/// </Summary>
Public class DemoMethods
{
[Ajax. AjaxMethod]
Public string GetCustomerMac (string clientIP) // enter the Client IP address here. This function is used for testing. You can also write other simple functions instead.
{
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 ();
}
}
} |