download a. NET AJAX Development Kit, which includes Ajax for ASP2.0 and the current ASP1.1 edition, detailed address see http://ajax.schwarz-interactive.de/, Next, start. 1. Create a new item, add a reference to the reference Ajax.dll,ajax.dll is located in the downloaded compressed package. 2. Establish HttpHandler, add in web.config <configuration>
<system.web>
<add verb= "Post,get" path= "Ajax/*.ashx" type= "Ajax.pagehandlerfactory, Ajax"/>
<system.web>
</configuration> 3. Create a new class Demomethods, this class implementation gets 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 client IP here, this function knowledge test, you can also write a other simple function 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 ();
}
}} 4. Write JavaScript, create a new file named Default.js 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 Refer to Default.js on the page <script Language= "javascript" src= "Default.js" ></script> Add in the onclick event of input
<input style= "Z-INDEX:101; left:392px; Position:absolute; top:176px "type=" button " value= "Client Get IP" > 6. Add the Page_Load event to the page page private void Page_Load (object sender, System.EventArgs e)
{
Place user code here to initialize page
Ajax.Utility.RegisterTypeForAjax (typeof (Ajaxsample.demomethods));
} Note: in typeof (Ajaxsample.demomethods), Ajaxsample is a namespace, Demomethods is the class that contains the method to invoke, that is, step 3rd above. New Class Demomethods 7. Modify the Global.asax Application_Start event and set the Ajax Handlerpath: protected void Application_Start (Object sender, EventArgs e)
{
Ajax.Utility.HandlerPath = "Ajax";
} Run to see the effect. is the MAC address of the client that is not refreshed on the server side? It should be noted that this version of. NET AJAX requires manual global.asax plus Ajax.Utility.HandlerPath = "Ajax"; Configuration file web.config must add HttpHandler configuration information! The new version of the development package has not had time to experience, it is estimated that the new version will be more convenient, may remove the manual settings Global.asax Application_Start event plus Ajax.Utility.HandlerPath = "Ajax"; and other troublesome settings! |