Is it best to check for a null User when trying to access UserID or should I assign an anonymous account? Or other?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You should check to see if there is no current user, and then create a new user account automatically and log them in, behind the scenes. If you use cookies (and assuming the user has them enabled), subsequent visits by this “anonymous user” will still map to the same account in your user repository, which is useful for tracking activity.
You can automatically put users into “registered” and “automatic/anonymous” groups. This makes it easy for your code to discern how to behave – for example, deciding whether to show “Log in” or “My Account” links by whether the current user is a member of the “anonymous” group. It also makes it easier to migrate over a history of activity to a registered account if/when the user decides to do so.