ajax| Refresh | no refresh
Long heard of Ajax technology, the legend is a very bull thing, known as no refreshing, in fact, through JavaScript on the web, using asynchronous XMLHTTP request, to achieve a web interface without refreshing. Unfortunately has not experienced, have to listen to do PHP friends with PHP Ajax development package, and do a lot of cool things, so that the niche envy unceasingly.
Today we have a. NET AJAX Development Kit, which includes Ajax for ASP2.0 and the current ASP1.1 edition, with a 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 <configuration>
<system.web>
<httpHandlers>
<add verb="POST,GET" path="ajax/*.ashx" type="Ajax.PageHandlerFactory, Ajax" />
</httpHandlers>
...
<system.web>
</configuration>
in web.config 3. Create a new class Demomethods, this class implementation gets 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, 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:
Add in the onclick event of input
value= "Client Get IP" >
6. 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 not the refresh on the server to get to the client's MAC address??
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! Look forward to ing ...