I have an ASP.NET MVC application and I want to be able to perform some logic 'just once' per page request. More specifically, I need to check details surrounding the logged in users role 'just once', each time they request a page within the application. I need to check the DB to see if their role has been changed since (flag in the db) and if so, log them out and redirect them back to the login screen.
I started off by creating a Base Controller and putting this logic inside the base class Initialize method, which works fine. The problem is that this particular initialize code is getting fired multiple times per page request (as there are numerous controllers in the application, many of which can get instantiated with any given page request.
I only want/need my logic (currently inside the base controller Initialize method) to occur once per page request though.
What approach would be recommended for this?