ASP.Net MVC3 FormsAuthentication overall logged-in event

338 views Asked by At

I have an ASP.Net MVC3 app. When the LogIn action is called, I use the MembershipProvider to validate the user and FormsAuthentication to set the cookie.

Additionally, I get some info about the user from a database and store it in Session.

When the user subsequently visits the site, they're already authenticated via the cookie, and I'm looking for somewhere to hook into so I can fetch the info about the user from the database again.

Is HttpApplication.AuthorizeRequest() the best place to do this? Obviously this is called for every request so I was hoping there was something I could use that just indicated the user had been authenticated - either explicitly after logging in or when they're authenticated automatically.

1

There are 1 answers

0
Andy T On BEST ANSWER

There are several events that get triggered on every request, HttpApplication.AuthorizeRequest() should work.

In order to only fetch from the database for logged in users, you can check the Name property of User.Identity which only gets set once the user authenticates:

if(!string.IsEmpty(User.Identity.Name))
{
 //make call to database
}