In the previous ASP.NET MVC, you can turn on the anonymous identification easily by adding 1 line in your web.config
:
<anonymousIdentification enabled="true" />
We can use the anonymous identification, i.e., Request.AnonymousID
to identify unauthenticated users on your site. This is pretty useful for eCommerce experience when you need to save the items in the shopping cart against visitors.
More info in: http://www.toplinestrategies.com/blogs/net/anonymous-identification-mvc
The Problem:
Request.AnonymousID
comes from System.Web
, and it's gone with ASP.NET Core.
Questions:
- How can we enable anonymous identification in ASP.NET Core MVC?
- If 1 is not possible, how would you "identify" visitors on your site?
Note: I don't want to use Sessions to store objects.
I coded a solution on my own. It is a middleware for ASP.NET Core that mimics the old behavior.
You can find the package on NuGet as AnonymousId (ReturnTrue.AspNetCore.Identity.Anonymous) and the source code on GitHub.
I'm new to the whole world of ASP.NET Core so please let me know of any bug, improvement, advice, correction...
The basic usage is: