// GET: Account/Logout
        public ActionResult Logout()
        {
            GenFx.AddToUserLog("Logout");
            //HttpContext.Response.Cache.SetExpires(DateTime.UtcNow.AddHours(-1));
            //HttpContext.Response.Cache.SetCacheability(HttpCacheability.NoCache);
            //HttpContext.Response.Cache.SetNoStore();
            // Response.Buffer = true;
            //Response.ExpiresAbsolute = DateTime.Now.AddDays(-1d);
            // Response.Expires = -1000;
            // Response.CacheControl = "no-cache";
            // Response.Cache.SetNoStore();
            Session.Clear();
            Session.Abandon();
            Session.RemoveAll();
            FormsAuthentication.SignOut();//you write this when you use FormsAuthentication

            return(RedirectToAction("Login", "Account"));
        }
        public ActionResult Login(LoginViewModel model, string returnUrl)
        {
            // Lets first check if the Model is valid or not
            if (ModelState.IsValid)
            {
                using (DBAuthContext entities = new DBAuthContext())
                {
                    string username = model.LoginName;
                    string password = model.Password;



                    bool CheckUserActiveornot = entities.Users.Any(user => user.LoginName == username && user.IsActive == false);
                    if (CheckUserActiveornot)
                    {
                        Session["siteMsgTyp"] = "error";
                        //Congrats on signing up for Zoom!In order to activate your account please click the button below to verify your email address:
                        Session["siteMsg"] = "Please Activate Your Account using link send your Email Address";
                        return(RedirectToAction("Login", "Account"));
                    }


                    // Now if our password was enctypted or hashed we would have done the
                    // same operation on the user entered password here, But for now
                    // since the password is in plain text lets just authenticate directly

                    bool userValid = entities.Users.Any(user => user.LoginName == username && user.Password == password);

                    // User found in the database
                    if (userValid)
                    {
                        //var userData = "";

                        //var identity = new ClaimsIdentity(new[] { new Claim(ClaimTypes.Name, username), }, DefaultAuthenticationTypes.ApplicationCookie);
                        //var ticket = new FormsAuthenticationTicket(1, username, DateTime.UtcNow, DateTime.UtcNow.AddMinutes(30), false, userData, FormsAuthentication.FormsCookiePath);
                        //var encryptedTicket = FormsAuthentication.Encrypt(ticket);
                        //var authCookie = new HttpCookie(FormsAuthentication.FormsCookieName, encryptedTicket) { HttpOnly = true };
                        //Response.Cookies.Add(authCookie);
                        //AuthenticationManager.SignIn(identity);

                        FormsAuthentication.SetAuthCookie(username, false);

                        //Update User Log
                        long userid = entities.Users.Where(user => user.LoginName == username && user.Password == password).Select(user => user.ID).Single();
                        GenFx.AddToUserLog("Login", userid);


                        if (model.ChkRememberMe.Equals(true))
                        {
                            Response.Cookies["UserName"].Expires = DateTime.Now.AddDays(30);
                            Response.Cookies["Password"].Expires = DateTime.Now.AddDays(30);
                        }
                        else
                        {
                            Response.Cookies["UserName"].Expires = DateTime.Now.AddDays(-1);
                            Response.Cookies["Password"].Expires = DateTime.Now.AddDays(-1);
                        }
                        Response.Cookies["UserName"].Value = model.LoginName;
                        Response.Cookies["Password"].Value = model.Password;

                        if (Url.IsLocalUrl(returnUrl) && returnUrl.Length > 1 && returnUrl.StartsWith("/") &&
                            !returnUrl.StartsWith("//") && !returnUrl.StartsWith("/\\"))
                        {
                            return(Redirect(returnUrl));
                        }
                        else
                        {
                            return(RedirectToAction("Index", "Home"));
                        }
                    }
                    else
                    {
                        ModelState.AddModelError("", "The user name or password provided is incorrect.");
                    }
                }
            }

            // If we got this far, something failed, redisplay form
            return(View(model));
        }