Ejemplo n.º 1
0
        protected override void OnActionExecuting(ActionExecutingContext filterContext)
        {
            #region 安装检测
            if (!MvcApplication.IsInstall)
            {
                filterContext.Result = Redirect("/Installer/Default.aspx");
                return; //未安装 终止
            }
            #endregion


            string tagStr = Request.Params["tag"];
            #region 设置企业标识

            long enterpriseId = 0;
            if (MvcApplication.IsAutoConn)
            {
                #region 读取APP加密企业ID

                if (enterpriseId == 0)
                {
                    //手机登录时候做处理
                    string userAgent       = Request.UserAgent;
                    string enterPriseValue = Request.Headers["YSWL_SAAS_EnterpriseID"];
                    string userValue       = Request.Headers["YSWL_SAAS_UserName"];
                    if (!string.IsNullOrEmpty(userAgent) && userAgent.Contains("ys56") &&
                        !string.IsNullOrEmpty(enterPriseValue) && !string.IsNullOrEmpty(userValue))
                    {
                        enterpriseId = Common.DEncrypt.DEncrypt.ConvertToNumber(enterPriseValue);
                    }
                }
                #endregion

                //优先处理传值过来的
                if (!string.IsNullOrWhiteSpace(tagStr))
                {
                    enterpriseId = Common.DEncrypt.DEncrypt.ConvertToNumber(tagStr);
                }

                if (enterpriseId == 0)
                {
                    Session.Timeout = 60;
                    enterpriseId    = Globals.SafeLong(Session["YSWL_Auto_EnterpriseID"], 0);//保存在session里面
                }

                //Shop域名
                if (enterpriseId == 0 && MvcApplication.ProductInfo.Contains("Mall"))
                {
                    string host = string.Empty;
                    if (filterContext.HttpContext.Request.Url != null)
                    {
                        host = filterContext.HttpContext.Request.Url.Host.ToLower();
                    }
                }

                if (enterpriseId == 0)
                {
                    //获取cookie中的企业标识
                    string tag = Common.Cookies.getKeyCookie("YSWL_SAAS_EnterpriseID");
                    if (!String.IsNullOrWhiteSpace(tag) && Common.DEncrypt.DEncrypt.ConvertToNumber(tag) > 0)
                    {
                        enterpriseId = Common.DEncrypt.DEncrypt.ConvertToNumber(tag);
                    }
                }

                if (enterpriseId < 1 && MvcApplication.ProductInfo.Contains("Mall"))
                {
                    //域名未登记, 返回404
                    filterContext.Result = new HttpNotFoundResult();
                    FileManage.WriteText(new System.Text.StringBuilder(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss:fff") + " filterContext.HttpContext.Request.Url.Host:" + filterContext.HttpContext.Request.Url.Host));
                    //                        FileManage.WriteText(new System.Text.StringBuilder("filterContext.HttpContext.Request.ServerVariables['HTTP_HOST']:" + filterContext.HttpContext.Request.ServerVariables["HTTP_HOST"]));
                    return;
                }

                if (enterpriseId > 0)
                {
                    Common.CallContextHelper.SetAutoTag(enterpriseId);
                    Session["YSWL_Auto_EnterpriseID"] = enterpriseId;
                }
                else
                {
                    string returnUrl = Common.ConfigHelper.GetConfigString("SAASLoginUrl");
                    filterContext.Result = Redirect(returnUrl);
                    return; //没有企业信息 跳转到SAAS登陆页面
                }
            }

            #region 个性域名检测
            //SaaS域名
            if (enterpriseId == 0 && MvcApplication.ProductInfo.Contains("SAAS"))
            {
                string host = string.Empty;
                if (filterContext.HttpContext.Request.Url != null)
                {
                    host = filterContext.HttpContext.Request.Url.Host.ToLower();
                }
                //启用个性域名访问
                int entId = 0;//SAASInfo.GetSAASEnterpriseIdByDomain(host);
                //FileManage.WriteText(new System.Text.StringBuilder(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss:fff") + host + " entId:" + entId));
                if (entId < 0)
                {
                    //域名未登记, 返回404
                    filterContext.Result = new HttpNotFoundResult();
                    FileManage.WriteText(new System.Text.StringBuilder(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss:fff") + " filterContext.HttpContext.Request.Url.Host:" + filterContext.HttpContext.Request.Url.Host));
                    //                        FileManage.WriteText(new System.Text.StringBuilder("filterContext.HttpContext.Request.ServerVariables['HTTP_HOST']:" + filterContext.HttpContext.Request.ServerVariables["HTTP_HOST"]));
                    return;
                }
                if (entId > 0)
                {
                    Common.CallContextHelper.SetAutoTag(entId);
                    Session["YSWL_Auto_EnterpriseID"] = entId;
                }
            }
            #endregion
            #endregion

            #region 动态获取当前区域的基础路径
            ViewBag.CurrentArea = CurrentArea = MvcApplication.GetCurrentAreaRoute(
                filterContext.RouteData.DataTokens["area"]);
            ViewBag.BasePath = MvcApplication.GetCurrentRoutePath(CurrentArea);
            #endregion


            #region 静态站域名
            ViewBag.CurrentArea = CurrentArea = MvcApplication.GetCurrentAreaRoute(
                filterContext.RouteData.DataTokens["area"]);
            ViewBag.BasePath = MvcApplication.GetCurrentRoutePath(CurrentArea);

            ViewBag.StaticHost = MvcApplication.StaticHost;
            #endregion

            #region 获取网站公共设置数据
            CurrentThemeName = MvcApplication.GetCurrentThemeName(CurrentArea);
            //DONE: 更正为动态区域, 模版使用主区域Check是否存在 BEN Modify 2013-05-17
            CurrentThemeName = System.IO.Directory.Exists(
                filterContext.HttpContext.Server.MapPath(
                    "/Areas/" + MvcApplication.MainAreaRoute + "/Themes/" + CurrentThemeName))
                            ? CurrentThemeName
                            : "Default";

            CurrentThemeViewPath = MvcApplication.GetCurrentViewPath(CurrentArea);

            //TODO: 应更正为一个值去处理 TO: 涂 BEN ADD 2013-05-17
            if (CurrentThemeName == "TufenXiang")
            {
                IncludeProduct      = false;
                UserAlbumDetailType = 0;
            }
            ViewBag.SiteName = MvcApplication.SiteName;
            #endregion

            ViewBag.CurrentUserId = -1;
#if isFirstProgram
            //加载已登录用户对象和Style数据, 由子类实现
            if (!InitializeComponent(filterContext))
            {
                return;
            }
#else
            if (InitializeComponent(requestContext.HttpContext))
            {
                base.Initialize(requestContext);
            }
#endif
            //SingleLogin slogin = new SingleLogin();
            //if (slogin.ValidateForceLogin())
            //{
            //    requestContext.HttpContext.Response.Write("<script defer>window.alert('" + Resources.Site.TooltipForceLogin + "');parent.location='" + DefaultLogin + "';</script>");
            //}

            Actions bllAction = new Actions();
            ActHashtab = bllAction.GetHashListByCache();
            if (ActHashtab != null && UserPrincipal != null)
            {
                if (!UserPrincipal.HasPermissionID(GetPermidByActID(Act_DeleteList)))
                {
                    ViewBag.DeleteAuthority = true;
                }
            }
            base.OnActionExecuting(filterContext);
        }