• Http 协议 请求 响应


     今天 在做.net mvc 项目中 关于权限限定模块 通过重载Controller 的OnActionExecuting方法 进行 action调用前的验证

     protected override void OnActionExecuting(ActionExecutingContext filterContext)
            {
                base.OnActionExecuting(filterContext);

                #region 用户权限验证
                            String str =Request.Url.AbsoluteUri;
                            string[] strs = str.Split('/');
                           
                            if (strs.Count() >= 4)
                            {   
                                string skey = strs[3];

                                if (skey != "Login")
                                {
                                    #region 用户登陆验证
                                    if (Session["UserID"] == null || Session["current_user"] == null)
                                    {
                                        Session["alertInformation"] = "页面已经过期,请重新登陆!";
                                        //filterContext.HttpContext.
                                        Response.Redirect("/Login/Index");
                                        //Response.Redirect("/LossCancel/Index");
                                        Response.End();
                                      return;
                                    }
                                    #endregion           
                                    if (skey != "Welcome")
                                    {
                                        Hashtable table = GetHashtable();
                                        foreach (DictionaryEntry de in table)
                                        {
                                            if (skey.Equals(de.Key))
                                            {
                                                bool permission = false;

                                                try
                                                {
                                                    permission = new IsPermission().IsTrue(de.Value.ToString(), (string)Session["UserID"]);
                                                }
                                                catch (Exception ex)
                                                {
                                                    logger.Error(ex);
                                                    Session["alertInformation"] = "页面已经过期,请重新登陆!";
                                                    Response.Redirect("/Login/Index");
                                                    Response.End();  //此处语句执行后 服务器就给浏览器响应 但本线程继续往下执行

                                                                              //服务器接到响应302 立刻启动一个线程访问服务器(url:/Login/Index)

                                                }
                                                if (!permission)
                                                {
                                                    Session["alertInfop"] = "对不起,您没有此权限!";
                                                    Response.Redirect("/Login/Welcome");
                                                    Response.End();
                                                }
                                            }
                                        }
                                    }
        
                       }
                     }                    
                        
                     #endregion       

      对于 Http协议:每一次请求 对应一次响应 服务器每得到一次请求 就建立一个线程对其进行处理 并响应

  • 相关阅读:
    修改程序堆栈的可执行属性
    【转】关于C语言生成不重复的随机数
    Apriori算法
    远程连接服务器端Jupyter Notebook
    Android KeyLogger Demo
    Windows消息钩取
    基址重定位表&.reloc节区
    调试UPX压缩的notepad
    PE文件格式
    apk逆向
  • 原文地址:https://www.cnblogs.com/xcwytu/p/2385210.html
Copyright © 2020-2023  润新知