TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Manoj Maharana
NA
362
127.9k
redirect to controller from global.asax when session End MVC
Jan 6 2017 2:48 AM
Here is my code in global.asax:
protected
void
Application_Start()
{
AreaRegistration.RegisterAllAreas();
WebApiConfig.Register(GlobalConfiguration.Configuration);
FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
RouteConfig.RegisterRoutes(RouteTable.Routes);
BundleConfig.RegisterBundles(BundleTable.Bundles);
AuthConfig.RegisterAuth();
}
//void Session_OnEnd()
//{
// RouteData routeData = new RouteData();
// routeData.Values.Add("controller", "Home");
// routeData.Values.Add("action", "logout");
// //routeData.Values.Add("Summary", "Error");
// //routeData.Values.Add("Description", ex.Message);
// IController controller = new HomeController();
// controller.Execute(new RequestContext(new HttpContextWrapper(Context), routeData));
//}
//protected void Session_Start(object src, EventArgs e)
//{
// 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);
// Response.Redirect("/Home/logout");
// }
// }
// }
//}
void
Session_OnEnd(
object
sender, EventArgs e)
{
//if (Session.IsNewSession)
//Response.RedirectToRoute("logout", "Home");
//RouteData routeData = new RouteData();
//routeData.Values.Add("controller", "Home");
//routeData.Values.Add("action", "logout");
////routeData.Values.Add("Summary", "Error");
////routeData.Values.Add("Description", ex.Message);
//IController controller = new HomeController();
//controller.Execute(new RequestContext(new HttpContextWrapper(Context), routeData));
// HttpContext.Current.RewritePath("Home/logout");
//Response.Redirect("~/Home/logout");
//HttpContext.Current.Response.Redirect("~/Home/logout");
}
i want to redirect when session end occurs after some time(1 minutes).
this is my
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:
: 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???
Reply
Answers (
2
)
How to set datagridview size according to data fetch
SQL Server : return column names based on a record's value