<configuration>lt;system.web>lt;httphandlers>lt;add verb="post,get" path="ajax/*.ashx"type="ajax.pagehandlerfactory,ajax" />lt;/httphandlers> <system.web>lt;/configuration>
using system;using system.web;namespace ajaxsample{/**//// <summary>/// summary description for methods./// </summary>ublic class demomethods{[ajax.ajaxmethod]ublic string getcustomermac(string clientip) //這里輸入客戶端ip,這個函數知識測試用,你也可以寫一個其他的簡單一點的函數代替{ tring mac = "";system.diagnostics.process process =new system.diagnostics.process();rocess.startinfo.filename = "nbtstat";rocess.startinfo.arguments = "-a "+clientip;rocess.startinfo.useshellexecute = false;rocess.startinfo.createnowindow = true;rocess.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();}}}
function getmac(){var clientip="192.168.0.1";//document.getelementbyid("mac").value=demomethods.getcustomermac(clientip).valuealert(demomethods.getcustomermac(clientip).value);}
lt;script language="javascript"src="default.js"></script>
lt;input type="button"
value="客戶端獲取ip" >
6.在page頁面的page_load事件中加上
private void page_load(object sender, system.eventargs e){// 在此處放置用戶代碼以初始化頁面ajax.utility.registertypeforajax(typeof(ajaxsample.demomethods));}
protected void application_start(object sender, eventargs e){ajax.utility.handlerpath = "ajax";}
新聞熱點
疑難解答
圖片精選