. NET Ajax Non-refresh technology examples

Source: Internet
Author: User
Tags config manual get ip
ajax| Refresh | no refresh | details download 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 and add in 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, 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 the client IP here. This function is used for knowledge testing. You can also write a simpler 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 to refer to Default.js on the page:

   
 Lt;script language= "javascript" src= "Default.js" ></script>

Add in the onclick event of input

   
    Lt;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));}private void Page_Load (object sender, System.EventArgs e)
  {
    // Place user code here to initialize the 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!


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.