Reputation: 129
I am writhing a simple online game , in a specific time , every day , the game will be updated and when the time comes , first I need to log out users. In "Application_Start" function in Global.asax , I initialize the timer and when it ticks , the method "UpdateGame" , which I wrote it in Global.asax is called. here is the method:
public static void UpdateGame()
{
AccountController account = new AccountController();
AdminController admin = new AdminController();
HomeController home = new HomeController();
account.LogOff();
admin.ChechHireEndTimes();
admin.CheckRentsEndTimes();
admin.UpdateRankings();
admin.InitializeAbstractTimes();
}
when it came to the logOff() , it freezes. here is the logOff method:
[Authorize]
public ActionResult LogOff()
{
FormsService.SignOut();
return RedirectToAction("Index", "Home");
}
I worked a lot on it but it seems that because the logout is not called with a http request , it is not working as when the user press the logout button.
so my question is that how can I invoke a controller's action like this one , from inside Global.asax?
Upvotes: 0
Views: 1404
Reputation: 49195
You cannot do log off action in global.asax without a user context. Which user should be logged off when you do account.LogOff()
? I believe that redirection (RedirectToAction
) with app_start is probably freezing your app.
For logging out all users, you may use a LastUpdated
global flag (set by UpdateGame method to current time). While logging in, you can put the LastUpdated value into user session and in each request, check this value with the global value. If global value is higher then you have log-out the current user by invoking your log off method.
Upvotes: 1