. NET AJAX Brushless new technology

Source: Internet
Author: User
Tags add object config get ip net reference string version
ajax| Refresh | no refresh
"Guide" Ajax technology, known as no refresh, is actually on the Web through JavaScript, using asynchronous XMLHTTP request, to achieve a web interface without refreshing. This article takes you through an example to experience. NET AJAX No Refresh technology ...

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!

<

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.