I cache information about the currently logged in user in the session. This info lazy loads whenever a CurrentUser
property on my global application class is used. It does this by calling GetUser() on my custom implementation of MembershipProvider, which either loads the user up from the session, or loads the user from the DB and throws the user object in the session.
How should I handle this scenario?
- User logs in.
- Administrator deletes user (or deactivates...the point is they can't log in any more).
- User's session expires.
- User navigates to a page or makes a request, or whatever.
Currently if this scenario occurs, NullReferenceExceptions are thrown all over the place, because the ASP .NET framework calls GetUser() which returns nothing because it can't find the user in the database (and there's nothing in the session because it expired).