Monday, March 21, 2016

Identify Anonymous Users in Asp.net

Identify anonymous users in asp.net

The first thing when we read about identifying anonymous users in asp.net mvc is "Why do we need to identify anonymous users?". Well the same thought had crossed my mind, but then when developing an e-commerce application, we needed anonymous users to add items to the shopping cart without logging in. We also needed these items to be loaded into the shopping cart, the next time they visited.

How do we do this?

Asp.net provides a guid accessed through the Request.AnonymousId property with which the user can be identified.
  1. Enable anonymous Identification

    Anonymous Identification need to be enabled, else Request.AnonymousId will be null.
    <configuration>
        <system.web>
          <anonymousIdentification enabled="true"/>
        </system.web>
      </configuration>
  2. Access the Anonymous Id

    Anonymous Id can be accessed through Request.AnonymousID property.

Hope this helps someone.

No comments:

Post a Comment