当前位置: 首页 > 图文教程 > 网站运营 > 网站优化 > 初次体验.NET Ajax无刷新技术

网站优化
增加网站外部链接16个方法
SEO2.0成功的十个步骤 向SEO和PR说再见
SEO不单单是关键词排名 还有整站优化
Google网页质量评定指导方针手册
五十七条让你成为搜索引擎优化高手的技巧
赵宜君:大型门户网站SEO实战总结
通过搜索结果 来增加网站的单向反向链接
我是如何让百度一天收录我的网站!
引以为戒:分析一些常见的网站作弊性手段
百度收录网站和清除网站的规则
css相关seo事项 前端人员写代码进入SEO
网页编码和搜索引擎优化
避免上当受骗:友情链接中不能忽视的细节
搜索引擎分析报告对SEO未来的影响
事实并非如此:常见几个对SEO的错误理解
百度K网站已经实施了精确打击 要重视起来
搜索引擎用户行为研究报告 对SEO的启示
百度优化VS谷歌优化 浅谈针对优化差异性
单页面网站如何优化
齐宁:垃圾链接依然存在 链接也能拉动内需

网站优化 中的 初次体验.NET Ajax无刷新技术


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-11-02   浏览: 130 ::
收藏到网摘: n/a

早就听说Ajax技术了,传说中是一种很牛的东西,号称无刷新,其实是在web上通过javascript,使用异步的xmlhttp请求,实现无刷新的web界面。可惜一直没有体验过, 先后听做PHP的朋友用过PHP的Ajax开发包,而且做了很多很酷的东西,使小生羡慕不已。 今天下了一个.net Ajax开发包,该开发包包括ASP2.0和目前ASP1.1版使用的Ajax,详细地址参见http://ajax.schwarz-interactive.de/,接下来,开工。

   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";
}

运行看看效果。是不是没有刷新就在服务器端取到客户端的MAC地址??

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

该开发包的新版本还没有来得及体验,估计新版本中会方便一些,可能会去掉手动的设置Global.asax的Application_Start事件中加上Ajax.Utility.HandlerPath = "ajax";以及其他麻烦的设置!期待ing……