How to preserve session using cookie
Microsoft Net Framework

How to preserve session using cookie?

How to preserve session all time until user is logged out


Just get value from cookie and reset it all time from cookie if session is nul,

Create a BaseController and  override   OnActionExecuting, when any action is called.     

  public override void OnActionExecuting(ActionExecutingContext filterContext)
        {
            if (SessionItems.Get(SessionKey.ACCOUNT) == null)
            {
                var ac = CookieHandler.GetCookies();
                if (ac != null && ac.AccountId > 0)
                {
                    var a = UnitOfWork.Accounts.AccountByEmail(ac.EmailAddress);                   
                    SessionItems.Add(SessionKey.ACCOUNT, a);
                }

            }

           
        }

 

Share This with your friend by choosing any social account


Upcoming Articles
You may also read following recent Post
Copyright Future Minutes © 2015- 2024 All Rights Reserved.   Terms of Service  |   Privacy Policy |  Contact US|  Pages|  Whats new?
Update on: Dec 20 2023 05:10 PM