I am able to intercept MVC 2 RC ASP.NET Session timeouts in the Global.asax.cs:
protected void Session_Start()
{
if (Context.Session != null)
{
if (Context.Session.IsNewSession)
{
string sCookieHeader = Request.Headers["Cookie"];
if ((null != sCookieHeader) && (sCookieHeader.IndexOf("ASP.NET_SessionId") >= 0))
{
// how to simulate it ???
// RedirectToAction(“ActionName”, “ControllerName”, route values);
}
}
}
}
The question is how to redirect program flow to a particular controller action. Basically, I would like to simulate MVC’s RedirectToAction(“ActionName”, “ControllerName”, route values) call inside Global.asax.cs.
I want to re-route the current request to another controller/action, while keeping the execution path exactly the same as if that controller/action - inside global.asax - was requested.
Looking forward for the MVC community input on the proposed solution along the following lines:
RouteData routeData = new RouteData();
routeData.Values.Add("controller", "HomeMain");
routeData.Values.Add("action", "SessionTimeout");
// Clear the error on server.
Server.ClearError();
Response.Clear();
// Call target Controller and pass the routeData.
IController HomeMainController = new HomeMainController();
HomeMainController.Execute(new RequestContext(
new HttpContextWrapper(Context), routeData));
Yitzhak
Member
20 Points
39 Posts
MVC 2 RC: ASP.NET Session timeout handling in Global.asax
Jan 28, 2010 07:29 PM|LINK
I am able to intercept MVC 2 RC ASP.NET Session timeouts in the Global.asax.cs:
protected void Session_Start() { if (Context.Session != null) { if (Context.Session.IsNewSession) { string sCookieHeader = Request.Headers["Cookie"]; if ((null != sCookieHeader) && (sCookieHeader.IndexOf("ASP.NET_SessionId") >= 0)) { // how to simulate it ??? // RedirectToAction(“ActionName”, “ControllerName”, route values); } } } }The question is how to redirect program flow to a particular controller action. Basically, I would like to simulate MVC’s RedirectToAction(“ActionName”, “ControllerName”, route values) call inside Global.asax.cs.
I want to re-route the current request to another controller/action, while keeping the execution path exactly the same as if that controller/action - inside global.asax - was requested.
Regards,
Yitzhak
ignatandrei
All-Star
134971 Points
21637 Posts
Moderator
MVP
Re: MVC 2 RC: ASP.NET Session timeout handling in Global.asax
Jan 28, 2010 07:52 PM|LINK
Yitzhak
Member
20 Points
39 Posts
Re: MVC 2 RC: ASP.NET Session timeout handling in Global.asax
Jan 28, 2010 08:17 PM|LINK
Hi ignatandrei,
I tried and the verdict is that the proposed solution is not working.
Beyond that this is MVC Web app. So I need to call an action method on a controller.
Regards,
Yitzhak
ignatandrei
All-Star
134971 Points
21637 Posts
Moderator
MVP
Re: MVC 2 RC: ASP.NET Session timeout handling in Global.asax
Jan 28, 2010 08:49 PM|LINK
Sorry
Try with Response.Redirect("~/controller/action/value")
MVC is , as WebForms, build over ASP.NET .
malcolms
All-Star
18687 Points
3124 Posts
MVP
Re: MVC 2 RC: ASP.NET Session timeout handling in Global.asax
Jan 28, 2010 11:15 PM|LINK
Another option that is different is to keep your session alive via a heartbeat. That way your session doesn't time out.
http://www.dotnetcurry.com/ShowArticle.aspx?ID=453
Yitzhak
Member
20 Points
39 Posts
Re: MVC 2 RC: ASP.NET Session timeout handling in Global.asax
Jan 29, 2010 12:23 AM|LINK
Response.Redirect("~/controller/action/value") idea is not working either.
I am getting into the infinite loop. The app. is calling the Session_Start() method again and again as a new session.
Regards,
Yitzhak
Yitzhak
Member
20 Points
39 Posts
Re: MVC 2 RC: ASP.NET Session timeout handling in Global.asax
Jan 29, 2010 02:03 AM|LINK
Looking forward for the MVC community input on the proposed solution along the following lines:
RouteData routeData = new RouteData(); routeData.Values.Add("controller", "HomeMain"); routeData.Values.Add("action", "SessionTimeout"); // Clear the error on server. Server.ClearError(); Response.Clear(); // Call target Controller and pass the routeData. IController HomeMainController = new HomeMainController(); HomeMainController.Execute(new RequestContext( new HttpContextWrapper(Context), routeData));Regards,
Yitzhak
ignatandrei
All-Star
134971 Points
21637 Posts
Moderator
MVP
Re: MVC 2 RC: ASP.NET Session timeout handling in Global.asax
Jan 29, 2010 07:07 AM|LINK
It works on my test without getting into the infinite loop ....
Yitzhak
Member
20 Points
39 Posts
Re: MVC 2 RC: ASP.NET Session timeout handling in Global.asax
Jan 29, 2010 01:40 PM|LINK
Hi ignatandrei
Response.Redirect("~/controller/action/value") is still a puzzle.
On my side the
Response.Redirect("~/HomeMain/SessionTimeout");
still gets into the infinite loop.
My environment has the following:
Please compare your environment against mine.
Regards,
Yitzhak
ignatandrei
All-Star
134971 Points
21637 Posts
Moderator
MVP
Re: MVC 2 RC: ASP.NET Session timeout handling in Global.asax
Jan 29, 2010 01:57 PM|LINK
Before, please remove the space betweeen HomeMain and /SessionTimeout in
Response.Redirect("~/HomeMain /SessionTimeout")
Thank you