一般处理程序用户登录验证

<script src="../js/jquery-1.8.0.min.js"></script>
    <script type="text/javascript">

        //function success(s) {
        //    debugger;
        //    alert(1);
        //    if (s.global) {
        //        trigger("ajaxSuccess", [xhr, s]);
        //    }
        //    // If a local callback was specified, fire it and pass it the data
        //    if (s.success && xhr.responseText != "unlogin") {
        //        s.success.call(callbackContext, data, status, xhr);
        //    }
        //}
        $(function () {
            debugger;
            alert(2);
            $.ajax({
                type: 'post',
                url: 'a.ashx',
                success:
            function (msg) {
                alert(msg);
              
                
                }

            })


        })
        $(document).ajaxSuccess(function (event, xhr, settings) {
            if (xhr.responseText == "unlogin") {
                window.top.location.href = "http://www.baidu.com";
                
            }
        })
        </script>

  

一般处理程序类后要加System.Web.SessionState.IRequiresSessionState接口,否则找不到HttpContext.Current.Session["aa"],

 public void ProcessRequest (HttpContext context) {
        context.Response.ContentType = "text/plain";
     
        if (HttpContext.Current.Request.UrlReferrer.ToString().ToLower().IndexOf("login.html") < 0)
        {
         
            if (HttpContext.Current.Session["aa"] == null )
            {
                HttpContext.Current.Response.Write("unlogin");
                HttpContext.Current.Response.End();
                //context.Response.Write("unlogin");
            }
        }
        //context.Response.Write("Hello World");
    }

原文地址:https://www.cnblogs.com/zhubenxi/p/5160379.html