コード例 #1
0
 protected void Application_Start()
 {
     AppDomain.CurrentDomain.UnhandledException += (sender, error) => File.AppendAllText("App_Data/Fatal.log", error.ExceptionObject.ToString() + "\r\n");
     ResourcesUtility ru = new ResourcesUtility(Server);
     ru.GenerateJSResources();
     FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
     RouteConfig.RegisterRoutes(RouteTable.Routes);
     BundleConfig.RegisterBundles(BundleTable.Bundles);
     ModelBinders.Binders.Add(typeof(EditAccountModel), new EditAccountModelBinder());
     //ModelBinders.Binders.Add(typeof(EditAccountModel), new LanguageObjectPreferencesBinder());
     //ModelBinders.Binders.DefaultBinder = new CustomModelBinder();
 }
コード例 #2
0
        public System.Web.Mvc.ActionResult LogIn(LogInModel loginModel)
        {
            if (ModelState.IsValid)
            {
                if (Membership.ValidateUser(loginModel.UserName, loginModel.Password))
                {
                    ResourcesUtility ru = new ResourcesUtility(Server);
                    ru.GenerateJSResources();

                    //AccountInfo user = HttpContext.Session["UserAccountInfo"] == null ? null : HttpContext.Session["UserAccountInfo"] as AccountInfo;
                    AccountInfo user = CurrentUser.Details();

                    bool isLogged = false;
                    isLogged = HttpContext.Session["UserLogged"] != null && (bool)HttpContext.Session["UserLogged"];

                    if (isLogged)
                    {
                        Session.Add("logged", true);
                        FormsAuthentication.SetAuthCookie(user.AccountId.ToString(), loginModel.RememberMe);

                        Session["UserAccountInfo"] = user;

                        //if (loginModel.RememberMe)
                        //{
                        //    HttpContext.Cache.Insert(user.AccountId.ToString(), user, null, System.Web.Caching.Cache.NoAbsoluteExpiration, TimeSpan.FromDays(365));
                        //}
                        //else if (HttpContext.Cache[user.AccountId.ToString()] != null)
                        //{
                        //    HttpContext.Cache.Remove(user.AccountId.ToString());
                        //}
                        HttpContext.Session.Remove("UserLogged");
                    }

                    if (user.Role == AccountRoles.Carer)
                    {
                        return RedirectToAction("List", "Users");
                    }
                    else if (user.Role == AccountRoles.User)
                    {
                        return RedirectToAction("New", "Documents");
                    }
                }
                else
                {
                    ViewData["ShowHead"] = true;
                    ModelState.AddModelError("", ClientDefault.LogIn_Log_In_Failed);
                }
            }

            return View("LogIn", loginModel);
        }