zoukankan      html  css  js  c++  java
  • 一般处理程序应用示例

    通过js调用ashx中的test()方法
    js:

    
            function test(id,pwd){
                $.ajax({
                    url: '/Tools/Handler.ashx?action=Log',
                    data:{id : id, pwd : pwd },
                    success: function (data){
                        alert(data);
                    }
                });
            }
    
    

    一般处理程序(ashx):

    
            using Newtonsoft.Json;
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.Script.Serialization;
    using System.Web.SessionState;
    
    namespace UAS2._0.Business.Common
    {
        /// <summary>
        /// Common 的摘要说明
        /// </summary>
        public class Common : IHttpHandler, IRequiresSessionState
        {
            public void ProcessRequest(HttpContext context)
            {
                context.Response.ContentType = "text/plain";
                //context.Response.Write("Hello World");
                string action = context.Request["action"].ToString();
                switch (action)
                {
                    case "PointForAjax":
                        PointForAjax(context);
                        break;
                    case "Log":
                        Log(context);
                        break;
                    default:
                        break;
                }
            }
            public bool IsReusable
            {
                get
                {
                    return true;
                }
            }
            //公共js-Ajax返回状态码处理-数据库-字典-获取状态码
            public  void PointForAjax(HttpContext context)
            {
                string field = context.Request["field"].ToString();
                List<sysDictionary> dictionaryList = DBManage.GetListBySql<sysDictionary>("SELECT * FROM [sys_Dictionary] where [field]='" + field + "'");
                context.Response.Write(new JavaScriptSerializer().Serialize(dictionaryList));
            }
            //记录日志
            public void Log(HttpContext context)
            {
                string source = context.ApplicationInstance.Request.UrlReferrer.AbsolutePath;
                string warnAction = context.Request["warnAction"].ToString();
                var user= context.Session["user"];
                context.Session.Abandon();//清除全部Session,即退出登录
            }
        }
    }
    
    
    

    参考:
    https://blog.csdn.net/lily233/article/details/78752936

  • 相关阅读:
    两个单向链表的第一个公共节点
    c字符输出
    堆排序
    归并排序
    LR中,URL -based script与HTML -based script区别
    loadrunner文本检查点
    Loadrunner集合点Rendezvous知识
    连接池(Connection Pool)技术
    lucene 查询 (转载)
    Lucene + Hadoop 分布式搜索运行框架 Nut 1.0a9转自http://www.linuxidc.com/Linux/2012-02/53113.htm
  • 原文地址:https://www.cnblogs.com/jsll/p/12930859.html
Copyright © 2011-2022 走看看