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.
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.)?
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With