7

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.)?

2
  • Do both environments (dev & test) share the same hostname?
    – haim770
    Commented Feb 9, 2016 at 7:59
  • @haim770 The dev-site is accessed through localhost:61615 on my machine, while the test-site has an actual hostname. The site is a sub-site (eg. mysite.domain.com) if that makes any difference. Commented Feb 9, 2016 at 8:06

1 Answer 1

1

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.

2
  • The Anonymous Authentication Module is present in IIS Manager under "Modules" for the site. Could this be a configuration issue elsewhere in IIS? Commented Feb 9, 2016 at 15:04
  • Yes. IIS configuration can be overwritten at several levels. You will have to check if the configuration was modified anywhere Commented Sep 2, 2016 at 6:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.