简体   繁体   中英

How to reset AnonymousID in ASP.NET MVC?

On some reasons some users get null AnonymousID on my site. I want to reset them to new Guids , but how?

Trying to do this:

public void AnonymousIdentification_Creating(object sender, 
   AnonymousIdentificationEventArgs args)
{ 
    args.AnonymousID = Guid.NewGuid().ToString();
}

And this:

protected void Application_EndRequest(object sender, EventArgs e)
{
   if (Request.IsAuthenticated && Request.AnonymousID == null)
   {
   System.Web.Security. 
       AnonymousIdentificationModule.ClearAnonymousIdentifier();
   }
}

AnonymousID reset to null, but not assing new. And no AnonymousIdentification_Creating invokes.

It there any way manually set or reset to new AnonymousID ?

UPDATED: <anonymousIdentification enabled="true" /> also.

By default Anonymous Identification is disabled in MVC. To enable this, you need to add the following tag in web.config under configuration => system.web tag:

<anonymousIdentification enabled="true" />

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM