Click here to Skip to main content
15,891,905 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi there, good morning. I am stuck in an application where I need to recover the lost session. If person is undergoing a test,just like the prometric center, faced the power-cut issue,he should not lose the session state that is , when the power comes back, his test should also be recovered. please help me on this.


best regards,
Posted

1 solution

To achive this I had use cookies.The approch I follow is below
Create a BaseController Class and inherit all your controller with this BaseController.
In your BaseController ,Override onActionExecuting Method like below

C#
public class BaseController : Controller
   {

       protected override void OnActionExecuting(ActionExecutingContext filterContext)
       {
           string value =cookie //assign you cookie value.

           base.OnActionExecuting(filterContext);
           string controllerName = filterContext.Controller.GetType().Name;
           string actionName = filterContext.ActionDescriptor.ActionName;
           if (string.IsNullOrEmpty(value))
           {
               if (!controllerName.Equals(typeof(LoginController).Name))
                   filterContext.Result = new RedirectToRouteResult(
                       new RouteValueDictionary {
                       { "Controller", "Login" },
                       { "Action", "Index" }
                       });
           }
           else
           {
               if (string.IsNullOrEmpty(Session["UserId"])
               {
                  //code to re-initilize your session from cookies
               }
              
           }
       }
 
Share this answer
 
Comments
JBobby 3-Jul-14 21:35pm    
thanks for replying. :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900