Search code examples
asp.net-coreasp.net-identity

Can I follow a not logged in user using Asp.Net Core Identity?


The question is quite explicit I think.

I have logged-in users and not logged-in users, I would like to be able to identify an user who is coming back on the website few days later (I don't need informations about him, I just need to know that this user came back for statistics purposes).

Can I use Microsoft Identity for that? Or should I create manually a cookie with a guid and deal when the user is logged or not?


Solution

  • Y0u could probably hack Identity to do this but your other idea of using a cookie with an identifier is a better one. In order to use Identity you would need to create a user for each session you want to track, and then store that user's credentials in a cookie. The simplest thing would be to use a guid as both the user's id and password. Then when they return, if you detect that cookie, try to authenticate with it. But at that point you are doing the same thing you could have just done yourself.

    If you do build it yourself, I would recommend implementing it as middleware.