Reputation: 53
I have an .net mvc5 project which uses Microsoft.AspNet.Identity for authentication.
I want to detect/log when a user logs in to the application, both when the user has a "remember me" cookie, and if the user logs in manually.
I have already tried creating a custom AuthenticateFilter based on IAuthenticationFilter but both OnAuthentication and OnAuthenticationChallenge fires several times for every request.
I know I can add the code in the login action, but I also want to catch the users that are logging in with a cookie.
Is there anywhere else in the Identity code, I can override, and add my logging code?
Upvotes: 3
Views: 1416
Reputation: 470
There are some hook-s for this in the MVC's architecture. Implement one of these in Global.asax:
Upvotes: 1
Reputation: 28200
You can probably do this inside of ValidateIdentity on the Cookie middleware, since that will be called even if remember me is set.
Upvotes: 1