zoukankan      html  css  js  c++  java
  • 自定义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那么笨重,速度有所提升,由于访问局限性,安全性加强。

    Newd

    版权声明

    作者:扶我起来我还要敲

    地址:https://www.cnblogs.com/Newd/p/4765762.html

    © Newd 尊重知识产权,引用请注出处

    广告位

    (虚位以待,如有需要请私信)

  • 相关阅读:
    做才是得到
    常用工具汇总
    迎接2017
    新年礼物
    2017
    asp.net core 日志
    板子|无向图的割点
    11/06信竞快乐模拟赛
    动态规划复习
    894D
  • 原文地址:https://www.cnblogs.com/Newd/p/4765762.html
Copyright © 2011-2022 走看看