2

Is there a built-in way to handle a cookie-based Anonymous UserId between sessions in asp.net core, or do I need to roll my own / some third part thing? Just like Request.AnonymousID did in 4.x days.

Background

I have done a bunch of searching for "Asp.net core anonymous user id" and related things, and this seems like one of those things, that I feel like there must be a great solution for - but I am just not searching for the right keywords...

I did find something in github/nuget called AnonymousID, but is is quite old and has a lot of strange dependencies, that makes me weary to install it.

Kjensen
  • 12,447
  • 36
  • 109
  • 171

2 Answers2

1

I ended up taking https://github.com/aleripe/AnonymousId/tree/master/AnonymousId and just adapting it to 3.1 - and it works perfectly.

Kjensen
  • 12,447
  • 36
  • 109
  • 171
-5

You can also use the AllowAnonymous attribute to allow access by non-authenticated users to individual actions. For example:

[Authorize]
public class AccountController : Controller
{
    [AllowAnonymous]
    public ActionResult Login()
    {
    }

    public ActionResult Logout()
    {
    }
}

This would allow only authenticated users to the AccountController, except for the Login action, which is accessible by everyone, regardless of their authenticated or unauthenticated / anonymous status.

Reference: Simple authorization in ASP.NET Core

Community
  • 1
  • 1
crgolden
  • 4,332
  • 1
  • 22
  • 40