예제 #1
0
        public static string _host = ".kerlaii.com";//从数据库动态获取

        public void OnActionExecuting(ActionExecutingContext filterContext)
        {
            bool   isajax = filterContext.HttpContext.Request.IsAjaxRequest();
            UserPC user   = filterContext.HttpContext.Session["user"] as UserPC;

            string host = filterContext.HttpContext.Request.Url.Host;
            string key  = host.Replace(_host, "");

            //本地调试,模拟e0001企业  opera
            if (host.ToLower() == "localhost")
            {
                key = "e0001";
            }

            EnterpriseBll bll = new EnterpriseBll();

            string[] keys = bll.GetAllEnteriseKey();


            if (key != "opera" && !keys.Contains(key))
            {
                filterContext.Result = new HttpNotFoundResult();
                return;
                //没有该企业
            }
            filterContext.HttpContext.Session["enterpriseKey"] = key;
            if (check)
            {
                if (user == null)
                {
                    ReturnData <string> ret = new ReturnData <string>();
                    if (isajax)
                    {
                        ret.Status = false;
                        Dictionary <string, object> Identify = new Dictionary <string, object>();
                        Identify.Add("expired", true);
                        ret.Identify         = Identify;
                        filterContext.Result = new ContentResult()
                        {
                            Content = ret.GetJson()
                        };
                        return;
                    }
                    //跳转页面
                    filterContext.Result = new ContentResult()
                    {
                        Content = "<script>window.top.location.href ='/';</script>"
                    };
                    return;
                }
                LogAdapter.Write(user.UserBasic.EnterpriseID + "     " + key, LogAdapter.LogMode.ERROR);
                //当前用户不是当前企业
                if (user.UserBasic.EnterpriseID != key)
                {
                    filterContext.HttpContext.Response.Redirect("/Login");
                }
            }
        }