How to work with anonymous users in ASP.NETMembership

Is it better to check for a null user when trying to access the UserID, or assign an anonymous account? Or something else?

+1


a source to share


3 answers


You have to check if the current user exists and then automatically create a new user account and log into it behind the scenes. If you use cookies (and assume that the user has enabled them), subsequent visits by that "anonymous user" will still appear in the same account in your user repository, which is useful for tracking activity.



You can automatically place users in "registered" and "auto / anonymous" groups. This makes it easy to recognize the behavior of your code, such as deciding whether to show "Login" or "My Account" links, or whether the current user is a member of an "anonymous" group. It also makes it easier to migrate the activity history to the registered account if / when the user chooses to do so.

+2


a source


In ASP.NET membership, you can call the following function to check if the user is logged in / authenticated / anonymous or not ...



User.Identity.IsAuthenticated()

      

+4


a source


If you are on the page, the property User.Identity.IsAuthenticated()

will give you a boolean value. If you are not on the page (i.e. want to check a class method), you need to import the namespace System.Web.HttpContext

.

0


a source







All Articles