0

I've got an MVC 4 site where I'm using Forms Authentication. I'm setting a cookie when a user logs in. The majority of my site does NOT require a user to be logged in though.

What I'd like to do, whenever a user FIRST accesses my site, I'd like to update my "LastLogon" that I have stored in my database table to the corresponding value (if Request.IsAuthenticated). But I don't want it to fire on EVERY page that the user accesses.

So, where do I track when the user first accesses my site? Is that in the Global.asax? Is Application_Start method for all first requests to a site, or is that when the website first loads after an iisreset?

0

I realized/found yesterday that in the Global.asax that there's a method available called "Session_Start". I believe that will work perfectly.

I could also use the Application_Request method, but I don't want to hit my SQL Server that often.

(I'm also thinking of adding it to the "Session_End" method in case they are on the site for along time...

Here's a link to the Global.asax methods available:

http://sandblogaspnet.blogspot.com/2008/03/methods-in-globalasax.html

Edit/Update:

I just stumbled across this article on CodeProject that appears to be the time that the cookie is ready:

http://www.codeproject.com/Articles/288631/Secure-ASP-NET-MVC-applications

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.