AnonymousIdentificationModule.ClearAnonymousIdentifier Method ()


Clears the anonymous cookie or identifier associated with a session.

Namespace:   System.Web.Security
Assembly:  System.Web (in System.Web.dll)

public static void ClearAnonymousIdentifier()

Exception Condition

Calling ClearAnonymousIdentifier when the anonymous identification is not enabled.


The user for the current request is anonymous.

The ClearAnonymousIdentifier method removes the anonymous identifier associated with a session on a Web site. Use the ClearAnonymousIdentifier method to remove the anonymous identifier associated with a session when the user switches to an authenticated session associated with a user ID, for example when the MigrateAnonymous event occurs.

Since a new anonymous identifier will be issued immediately if the current anonymous identifier is removed, the ClearAnonymousIdentifier method will throw a NotSupportedException if it is called while the session is identified by an anonymous identifier.

If the site is using cookies, the ClearAnonymousIdentifier method issues a clear cookie to remove the anonymous identifier from the browser. The clear cookie is issued even if an anonymous cookie was not sent on the previous request.

The clear cookie is constructed as follows:

  • If the browser supports empty strings in a cookie, the cookie is issued with the empty string as its value; otherwise, the cookie is issued with "NoCookie" as its value.

  • The values for the cookie name, path, and domain are set to the defaults configured in the Web application's configuration file.

  • The expiration date is set to October 12, 1999.

If the site is using cookieless authentication, and an anonymous identifier is present in the URL, the anonymous identifier is removed from the URL. No other changes are made to the address or query string. After the URL is modified, a redirect is issued to return to the currently executing page.

.NET Framework
Available since 2.0
Return to top