Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AnonymousId is always null

I have an ASP.NET MVC site. When errors occur on the site, I would like to log the exception along with the value of Request.AnonymousID, to be able to spot if one user is experiencing 20 errors, or 20 users experiencing the same error. The following has been added to the web.config file:

<system.web>
  <anonymousIdentification enabled="true" />
  ...
</system.web>

While developing in Visual Studio and using IIS Express, this works as intended. However, when the site is moved to the Test environment (which runs IIS 8.5 on Windows Server 2012 R2) the value of Request.AnonymousID is always null.

Anonymous Authentication has also been configured for the site in IIS. After each change in configuration I try restarting the site, recycling the application pool, and clearing cookies in my browser - nothing seems to work. The .ASPXANONYMOUS cookie gets generated, but the ID is always empty when I try to use it in the code.

I even tried creating a quick dummy-site that only shows the AnonymousId on the page, and it works on the Test environment, so I can't figure out what I am doing wrong in the actual site.

Any help would be greatly appreciated.


Edit 1: I've added the following to Global.asax, in order to generate a custom AnonymousId:
protected void AnonymousIdentification_Creating(object sender, AnonymousIdentificationEventArgs args)
{
    string id = string.Format("Test-{0}", Guid.NewGuid());
    args.AnonymousID = id;
}

Again, this works on my machine and on my dummy-site on the Test-server, but not in the actual site.

The site is a sub-site (e.g. mysite.domain.com), if that makes any difference. The dummy-site is also a sub-site, but here the anonymous authentication worked "out of the box".


Edit 2: It seems the AnonymousId is no longer null on the site in the Test-environment. It is now populated with the format supplied in the eventhandler added to Global.asax. So while it seems like I had set everything up correctly, I would still like to know what could have prevented the Id from being generated. Was it a configuration issue? Did I not do things in the correct order (restart server / recycle app pool, clear cookies, etc.)?

like image 750
Lars Kristensen Avatar asked Feb 09 '16 07:02

Lars Kristensen


1 Answers

This should work. There is no correlation between hostname and the ASPXANONYMOUS cookie

Check if Anonymous Authentication Module is installed on IIS and what is it set to. I have seen instances where this module is not installed.

like image 70
Kaushal Kumar Panday Avatar answered Sep 22 '22 06:09

Kaushal Kumar Panday