Manoj Maharana

Manoj Maharana

  • NA
  • 362
  • 126.7k

redirect to controller from global.asax when session End MVC

Jan 6 2017 2:48 AM
Here is my code in global.asax:
  1. protected void Application_Start()  
  2.     {  
  3.         AreaRegistration.RegisterAllAreas();  
  4.   
  5.         WebApiConfig.Register(GlobalConfiguration.Configuration);  
  6.         FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);  
  7.         RouteConfig.RegisterRoutes(RouteTable.Routes);  
  8.         BundleConfig.RegisterBundles(BundleTable.Bundles);  
  9.         AuthConfig.RegisterAuth();  
  10.     }  
  11.   
  12.     //void Session_OnEnd()  
  13.     //{  
  14.     //    RouteData routeData = new RouteData();  
  15.     //    routeData.Values.Add("controller", "Home");  
  16.     //    routeData.Values.Add("action", "logout");  
  17.     //    //routeData.Values.Add("Summary", "Error");  
  18.     //    //routeData.Values.Add("Description", ex.Message);  
  19.     //    IController controller = new HomeController();  
  20.     //    controller.Execute(new RequestContext(new HttpContextWrapper(Context), routeData));  
  21.     //}  
  22.   
  23.     //protected void Session_Start(object src, EventArgs e)  
  24.     //{  
  25.     //    if (Context.Session != null)  
  26.     //    {  
  27.     //        if (Context.Session.IsNewSession)  
  28.     //        {  
  29.     //            string sCookieHeader = Request.Headers["Cookie"];  
  30.     //            if ((null != sCookieHeader) && (sCookieHeader.IndexOf("ASP.NET_SessionId") >= 0))  
  31.     //            {  
  32.     //                // how to simulate it ???  
  33.     //                // RedirectToAction(“ActionName”, “ControllerName”,  route values);  
  34.     //                Response.Redirect("/Home/logout");  
  35.     //            }  
  36.     //        }  
  37.     //    }  
  38.     //}  
  39.   
  40.     void Session_OnEnd(object sender, EventArgs e)  
  41.     {  
  42.         //if (Session.IsNewSession)  
  43.         //Response.RedirectToRoute("logout", "Home");  
  44.   
  45.         //RouteData routeData = new RouteData();  
  46.         //routeData.Values.Add("controller", "Home");  
  47.         //routeData.Values.Add("action", "logout");  
  48.         ////routeData.Values.Add("Summary", "Error");  
  49.         ////routeData.Values.Add("Description", ex.Message);  
  50.         //IController controller = new HomeController();  
  51.         //controller.Execute(new RequestContext(new HttpContextWrapper(Context), routeData));  
  52.   
  53.         // HttpContext.Current.RewritePath("Home/logout");  
  54.         //Response.Redirect("~/Home/logout");  
  55.   
  56.         //HttpContext.Current.Response.Redirect("~/Home/logout");    
  57.   
  58.     }  
i want to redirect when session end occurs after some time(1 minutes).
this is my
  1. web.config(<sessionState mode="InProc" timeout="1" />)  
i have tried a lot of code..but not working.
when the Session_OnEnd occurs i want to redirect to Home controller.but the above code in Session_OnEnd not working any suggestion.
the error occurs in Session_OnEnd is:
  1. : An exception of type 'System.NullReferenceException' occurred in MyZefer.UI.dll but was not handled in user code Additional information: Object reference not set to an instance of an object. Object reference not set to an instance of an object.  
any suggestion??
how to redirect to controller???
 

Answers (2)