AnonymousId is always null

I have an ASP.NET MVC site. When errors occur on the site, I would like to write an exception along with the Request.AnonymousID value to determine if one user has 20 errors or 20 users experience the same error. The following has been added to the web.config :

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

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

Anonymous authentication has also been configured for the site in IIS. After each configuration change, I try to restart the site, reuse the application pool and clear cookies in my browser - nothing works. The .ASPXANONYMOUS cookie is created, but the identifier is always empty when I try to use it in code.

I even tried to create a quick dummy site that only Anonymous shows on the page, and it works in a test environment, so I canโ€™t understand what I'm doing wrong on the site itself.

Any help would be greatly appreciated.


Edit 1: I added the following to Global.asax to create 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 a test server, but not on the site itself.

A site is a sub-site (e.g. mysite .domain.com), if that matters. A mannequin site is also a sub-site, but anonymous authentication works out of the box.


Edit 2: It seems that AnonymousId no longer null on the site in a test environment. Now it is filled with the format added in the event handler added in Global.asax . Therefore, although it seems that I configured everything correctly, I still would like to know what could prevent the creation of an ID. Is this a configuration problem? Did I do something in the correct order (restarting the server / disposing of the application pool, clearing cookies, etc.)?

+7
c # asp.net-mvc iis
source share
1 answer

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

Check if the anonymous authentication module is installed in IIS and why it is installed. I saw instances where this module is not installed.

+1
source share

All Articles