自定义HttpHandler处理类

    1、创建自定义类型

    2、继承IHttpHandler接口,并实现

    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);
                    }
            });
优点,没有aspx那么笨重,速度有所提升,由于访问局限性,安全性加强。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值