It depends. If you use identifier 2.1, they introduced a new SignInManager class. This class wraps the OWIN AuthenticationManager class, which is actually responsible for signing the user. In asp.net 2.1, you'll see several SigninManager login methods, such as
PasswordSignInAsync ()
ExternalSignInAsync ()
SignInAsync () and
TwoFactorSignInAsync ().
After the user information is retrieved from the database and checks are performed, all of these methods will call AuthenticationManager.Signin () to actually sign the user. This would be an ideal place, but it is an interface element set by OWIN, so you cannot override its Signin method. Thus, the best place to capture user input would be the SigninManager.SigninAsync(...) method in my humble opinion. This is because if the credentials are valid and the user is not a medallion, etc. Etc. All methods described above, such as
- PasswordSignInAsync ()
- ExternalSignInAsync ()
- TwoFactorSignInAsync ()
click SigninManager.SigninAsync(...) . Since this method is virtual, you can override SigninManager in your class and do something like this
public override async Task SignInAsync(ApplicationUser user, bool isPersistent, bool rememberBrowser) { await base.SignInAsync(user, isPersistent, rememberBrowser); user.LastLogin= DateTime.Now; UserManager.Update(user); }
Note that by calling UserManager.Update (), you will be taken to the database, but I do not see how you can avoid this. Identification methods asp.net like to get into the database, and if you do not override their implementation, you will have to live with it. (Using SigninManager.PasswordSignin() without any configuration of the base classes, they get into the database 4 times in the database).
If you are not using the asp.net 2.1 identifier, the SigninManager class does not exist. (MS had a sample nuget project that had a similar helper class, but it was not part of the framework). You will need to find the method in this helper class and override (or change) the signin method.
As a final note, the documentation for identifying asp.net is not complete in my humble opinion, and the source code is not yet open. I used JetBrains DotPeek to view the code inside the Microsoft.AspNet.Identity.Owin assembly and the SigninManager class. The thread I mentioned to you (how each method somehow ends up pushing SigninAsync() ) is my interpretation of the code from DotPeek. Feel free to check and make sure that I donโt miss anything. Good luck.