1

I am trying to persist some data that I intend on using in the application in my HttpContext.User. However, when I go to another page/controller and I recheck HttpContext.User, its empty again. Is there a way to set this as persistent? I am not using any form of identity as my application relies on jwt

public IActionResult Index()
{
    var claims = new[]
    {
        new Claim("name", "Test"),
    };
    var identity = new ClaimsIdentity(claims, "basic");
    HttpContext.User = new ClaimsPrincipal(identity);
    return View();
}
Tetsuya Yamamoto
  • 24,297
  • 8
  • 39
  • 61
JianYA
  • 2,750
  • 8
  • 60
  • 136
  • HttpContext.User is not session. Please refer https://learn.microsoft.com/en-us/aspnet/core/security/?view=aspnetcore-2.1 on how to setup authentication and authorization – Ramesh Nov 14 '18 at 05:00
  • So this is impossible? How does a non jwt .net core application persist user data? I don't see any sessions or cookies being used in the devtools of chrome. – JianYA Nov 14 '18 at 05:03
  • What kind of authentication are you using / you need ? Cookie Based ? – Ramesh Nov 14 '18 at 05:06
  • When I login, I send my username and password to a rest api which returns a jwt token. I haven't set anything in my startup.cs. I'm quite lost now as I need to persist some items across the application but I cannot use stuff like Iauthorization as I use a rest api to validate a users role as well. – JianYA Nov 14 '18 at 05:12
  • 1
    Check the solution in [ASP.NET Core 2.1 Jwt setting custom claims](https://stackoverflow.com/a/53293615/6265620) – Edward Nov 14 '18 at 05:21

0 Answers0