zoukankan      html  css  js  c++  java
  • 体验.NET Ajax无刷新技术 dodo

     1. 新建一个项目,在引用中添加引用Ajax.dll,Ajax.dll位于下载的压缩包里面。

       2.建立HttpHandler,在web.config里面加上 <configuration>
    <system.web>
    <httpHandlers>
    <add verb="POST,GET" path="ajax/*.ashx" type="Ajax.PageHandlerFactory, Ajax" />
    </httpHandlers>
    ...
    <system.web>
    </configuration>
    3.新建一个类DemoMethods,这个类实现获取客户端MAC地址: 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.写javascript,新建一个名为default,js文件如下:

    function GetMac()
    {
    var clientIP="192.168.0.1";
    document.getElementById("Mac").value=DemoMethods.GetCustomerMac(clientIP).value
    alert(DemoMethods.GetCustomerMac(clientIP).value);
    }

    5.在某个Aspx页面放上一个html 的button

      在页面上 中引用default.js :

      在INPUT的onclick事件中加上onclick="javascript:GetMac()"

    value="客户端获取IP" onclick="javascript:GetMac();">

       6.修改Global.asax的Application_Start事件,设置Ajax的HandlerPath :

    protected void Application_Start(Object sender, EventArgs e)
    {
    Ajax.Utility.HandlerPath = "ajax";
    }

    需要注意的是:该版本的.net Ajax需要手工在中Global.asax加上Ajax.Utility.HandlerPath = "ajax"; 配置文件web.config必须加上HttpHandler的配置信息!

  • 相关阅读:
    WPF 自适应布局控件
    c# 将Datarow转成Datarowview
    C# 全局Hook在xp上不回调
    WPF datagrid AutoGenerateColumns隐藏部分列
    WPF wpf中按钮操作权限控制
    C# autofac配置文件中设置单例
    Castle ActiveRecord 二级缓存使用 异常记录
    VS2013 抛出 stackoverflow exception 的追踪
    CastleActiveRecord在多线程 事务提交时数据库资源竞争导致更新失败的测试结果记录
    WF4.0 工作流设计器 传入参数问题记录?
  • 原文地址:https://www.cnblogs.com/zgqys1980/p/469923.html
Copyright © 2011-2022 走看看