I tried Charlino's code in the Global.asax like this
protected void Application_BeginRequest(object sender, EventArgs e)
{
if ((Response.ContentType == "text/html") && (Request.IsAuthenticated))
{
}
}
However I was getting the Request.IsAuthenticated
false all the time.
So I moved the code to a method in my Site.Master page
like this
public void RegisterActivity()
{
if ((Response.ContentType == "text/html") && (Request.IsAuthenticated))
{
string userName = Page.User.Identity.Name;
UserManager userManager = new UserManager();
AppUser appUser = userManager.FindByName(userName);
appUser.LastActivityDate = DateTime.UtcNow;
userManager.Update(appUser);
}
}
I call the method from the Master page
Page_Load
event, and there it worked.
I'm using asp.net Identity
not Membership
but I added an AppUser
class inheriting from the IdentityUser
class and in the AppUser
class I added LastActivityDate property
.
This is in a WebForms Applicaction
not MVC
.