示例#1
0
        /// <summary>
        /// 载入登录
        /// </summary>
        /// <returns></returns>

        public ActionResult Index()
        {
            //Response.Cache.SetOmitVaryStar(true);
            if (!ConfigurationHelper.IsDevelopment())//到登录页直接清除之前的缓存
            {
                ClearLoginCookie();
            }

            var entityService = DependencyResolver.Current.GetService <ModuleService>();
            var enService     = DependencyResolver.Current.GetService <IModuleContract>();

            if (AuthorityHelper.IsVerified)
            {
                return(RedirectToAction("Index", "Home", new { area = "Authorities" }));
            }
            ViewBag.bgImg = "/Content/Images/login_bg_default.jpg";//默认登录背景图
            TemplateTheme theme = CacheAccess.GetCurTheme(_templateThemeContract, TemplateThemeFlag.ERP);

            if (theme.IsNotNull())
            {
                ViewBag.themePath = theme.Path;
                var themeExist = false;
                if (!theme.Path.IsNullOrEmpty())
                {
                    themeExist = FileHelper.ThemeIsExist(theme.Path);
                }
                ViewBag.themeExist = themeExist;
                if (theme.BackgroundImg.IsNotNullAndEmpty() && FileHelper.FileIsExist(theme.BackgroundImg))
                {
                    ViewBag.bgImg = theme.BackgroundImg;
                }
            }

            #region 登录加密用的密钥

            string tc_key = Guid.NewGuid().ToString("N").Substring(0, 16);
            ViewBag._tc_key = tc_key;
            HttpContext.Session["_tc_key"] = tc_key;//因为seesion会有一个失效时间,所以加先已session来验证,后来用cookie来验证

            FormsAuthenticationTicket ticket = new FormsAuthenticationTicket(2, "_tc_key", DateTime.Now, DateTime.MaxValue, false, tc_key);
            var cookieKey = new HttpCookie(ticket.Name, FormsAuthentication.Encrypt(ticket))
            {
                HttpOnly = true,
                Secure   = FormsAuthentication.RequireSSL,
                Domain   = FormsAuthentication.CookieDomain,
                Path     = FormsAuthentication.FormsCookiePath,
                Expires  = DateTime.MaxValue
            };
            HttpContext.Response.SetCookie(cookieKey);

            #endregion

            return(View());
        }
示例#2
0
        public override void OnActionExecuted(ActionExecutedContext filterContext)
        {
            base.OnActionExecuted(filterContext);

            isAjaxView = filterContext.HttpContext.Request.IsAjaxRequest() && isAjaxView;

            var viewResult = filterContext.Result as ViewResult;

            if (viewResult.IsNotNull())
            {
                var pageUrl   = GetCurPageUrl(filterContext);
                var curModule = this.BreadCrumb(viewResult, pageUrl);
                viewResult.ViewBag.BreadCrumb = curModule;
                viewResult.ViewBag.isAjaxView = isAjaxView;

                #region 判断是否启用新的主题

                TemplateTheme theme = CacheAccess.GetCurTheme(_templateThemeContract, TemplateThemeFlag.ERP);
                if (theme.IsNotNull())
                {
                    viewResult.ViewBag.themePath = theme.Path;
                    var themeExist = false;
                    if (!theme.Path.IsNullOrEmpty())
                    {
                        themeExist = FileHelper.ThemeIsExist(theme.Path);
                    }
                    viewResult.ViewBag.themeExist = themeExist;
                }
                #endregion

                if (!isAjaxView)
                {
                    viewResult.ViewBag.Menu = this.Menu(viewResult, curModule);
                }
            }
        }