自定義HttpHandler
1、創(chuàng)建自定義類型
2、繼承IHttpHandler接口,并實現(xiàn)
3、配置Web.Config文件,注冊類型
4、訪問
public class QuickMsgSatisticsHandler : IHttpHandler { HttpContext context = null; #region IHttpHandler 成員 public void ProcessRequest(HttpContext context) { this.context = context; context.Response.ContentType = "text/plain"; Common.DataManager.QuickInsert("SMS_QuickContentSatistics", new string[1] { "ID" }, new object[1] { GetRequestID }); } public bool IsReusable { get { throw new NotImplementedException(); } } public string GetRequestID { get { return this.context.Request.Form["id"]; } } #endregion }
<httpHandlers> <!--注意:verb謂詞,就是訪問方式(POST、GET等) path指示訪問路徑,type注冊類型(前面為類型名,后面為類型所在的程序集,用逗號隔開)--> <add verb="*" path="QuickMsgSatisticsHandler" type="ZXHomeProject.Web.SMS.QuickMsgSatisticsHandler,ZXHomeProject.Web"/> </httpHandlers>
$.ajax({ type: "POST", url: "QuickMsgSatisticsHandler", async : false, data: { id : $(elem).attr('msgid')}, dataType: "text", success: function(data,Status,XMLHttpRequest){ }, error: function(XMLHttpRequest, textStatus, errorThrown) { alert(errorThrown); } });
優(yōu)點,沒有aspx那么笨重,速度有所提升,由于訪問局限性,安全性加強。
Newd
版權聲明
作者:扶我起來我還要敲
地址:http://www.rzrgm.cn/Newd/p/4765762.html
? Newd 尊重知識產(chǎn)權,引用請注出處
廣告位
(虛位以待,如有需要請私信)
浙公網(wǎng)安備 33010602011771號