</script>[/code] 在INPUT的onclick事件中加上 onclick="javascript:GetMac()" 6.在page页面的Page_Load事件中加上 private void Page_Load(object sender, System.EventArgs e) { // 在此处放置用户代码以初始化页面 Ajax.Utility.RegisterTypeForAjax(typeof(AjaxSample.DemoMethods)); } 注意:typeof(AjaxSample.DemoMethods)中,AjaxSample是命名空间,DemoMethods是要包含要调用方法的类,即上面第3步.新建类DemoMethods 7.修改Global.asax的Application_Start事件,设置Ajax的HandlerPath : protected void Application_Start(Object sender, EventArgs e) { Ajax.Utility.HandlerPath = "ajax"; } 运行看看效果。是不是没有刷新就在服务器端取到客户端的MAC地址? 需要注意的是:该版本的.net Ajax需要手工在中Global.asax加上Ajax.Utility.HandlerPath = "ajax"; 配置文件web.config必须加上HttpHandler的配置信息! 该开发包的新版本还没有来得及体验,估计新版本中会方便一些,可能会去掉手动的设置Global.asax的Application_Start事件中加上Ajax.Utility.HandlerPath = "ajax";以及其他麻烦的设置!
共1条
1/1 1 跳转至页
.net Ajax无刷新技术
下载一个.net Ajax开发包,该开发包包括ASP2.0和目前ASP1.1版使用的Ajax,详细地址参见http://ajax.schwarz-interactive.de/,接下来,开始。
1. 新建一个项目,在引用中添加引用Ajax.dll,Ajax.dll位于下载的压缩包里面。
2.建立HttpHandler,在web.config里面加上
3.新建一个类DemoMethods,这个类实现获取客户端MAC地址:
using System;
using System.Web;
namespace AjaxSample
{
/**////
/// Summary description for Methods.
///
public class DemoMethods
{
[Ajax.AjaxMethod]
public string GetCustomerMac(string clientIP) //这里输入客户端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 :
[code]<script language="javascript" src="default.js">
</script>[/code] 在INPUT的onclick事件中加上 onclick="javascript:GetMac()" 6.在page页面的Page_Load事件中加上 private void Page_Load(object sender, System.EventArgs e) { // 在此处放置用户代码以初始化页面 Ajax.Utility.RegisterTypeForAjax(typeof(AjaxSample.DemoMethods)); } 注意:typeof(AjaxSample.DemoMethods)中,AjaxSample是命名空间,DemoMethods是要包含要调用方法的类,即上面第3步.新建类DemoMethods 7.修改Global.asax的Application_Start事件,设置Ajax的HandlerPath : protected void Application_Start(Object sender, EventArgs e) { Ajax.Utility.HandlerPath = "ajax"; } 运行看看效果。是不是没有刷新就在服务器端取到客户端的MAC地址? 需要注意的是:该版本的.net Ajax需要手工在中Global.asax加上Ajax.Utility.HandlerPath = "ajax"; 配置文件web.config必须加上HttpHandler的配置信息! 该开发包的新版本还没有来得及体验,估计新版本中会方便一些,可能会去掉手动的设置Global.asax的Application_Start事件中加上Ajax.Utility.HandlerPath = "ajax";以及其他麻烦的设置!
</script>[/code] 在INPUT的onclick事件中加上 onclick="javascript:GetMac()" 6.在page页面的Page_Load事件中加上 private void Page_Load(object sender, System.EventArgs e) { // 在此处放置用户代码以初始化页面 Ajax.Utility.RegisterTypeForAjax(typeof(AjaxSample.DemoMethods)); } 注意:typeof(AjaxSample.DemoMethods)中,AjaxSample是命名空间,DemoMethods是要包含要调用方法的类,即上面第3步.新建类DemoMethods 7.修改Global.asax的Application_Start事件,设置Ajax的HandlerPath : protected void Application_Start(Object sender, EventArgs e) { Ajax.Utility.HandlerPath = "ajax"; } 运行看看效果。是不是没有刷新就在服务器端取到客户端的MAC地址? 需要注意的是:该版本的.net Ajax需要手工在中Global.asax加上Ajax.Utility.HandlerPath = "ajax"; 配置文件web.config必须加上HttpHandler的配置信息! 该开发包的新版本还没有来得及体验,估计新版本中会方便一些,可能会去掉手动的设置Global.asax的Application_Start事件中加上Ajax.Utility.HandlerPath = "ajax";以及其他麻烦的设置!
关键词: 无刷 新技术
共1条
1/1 1 跳转至页
回复
我要赚赏金打赏帖 |
|
|---|---|
| PCF8574功能模块及其使用被打赏¥20元 | |
| 传感器LSM6DSO及LIS3MDL的功能检测被打赏¥18元 | |
| LPS25HB气压传感器及其检测被打赏¥18元 | |
| HTS221温湿度传感器及其检测被打赏¥18元 | |
| 【S32K3XX】HSE FW 版本更新被打赏¥21元 | |
| 基于ArduinoUNO开发板的AT24C02读写测试被打赏¥16元 | |
| TCS3472S传感器及其色彩检测被打赏¥19元 | |
| 【S32DS】S32K3 RTD7.0.1 HSE 组件配置报错问题解决被打赏¥27元 | |
| 【S32K3XX】MCME 启动 CORE1被打赏¥23元 | |
| AG32VH407下温度大气压传感器及其检测被打赏¥20元 | |
我要赚赏金
