Closed fabercs closed 5 years ago
I guess the User in HttpContext is not being set yet in ongoing request. It is filled up on subsequent requests, I saw that by changing the last line in UserSessionMiddleware
await _next.Invoke(context);
to
context.Response.Redirect("Home")
If this is the case, is above approach a sensible way to make this work (making a 302 request) for my case?
Indeed, SignIn only affects future requests. You could set HttpContext.User yourself for the current request.
got it, simply solved, thank you!!
Describe the bug
In my project, I want to make use of the cookie based authentication without using the identity infrastructure. I have my own user,role and claim tables. So I was following this.
Our project is in a tfs repo. When any member in the team tries to run the app, we always get a exception caused from HttpContext.User.Identity is filled up with all
null
values. But when debug it or run it for several times, mostly values somehow filled up, or not. Details below;To Reproduce
Steps to reproduce the behavior:
UserSessionMiddleware
As the request reaches to the view component where to get user data and bind to the view elements, it throws null object exception. In fact when I inspect the context's
User.Identity
object aftercontext.SignInAsync
, I can see that a new object sits there however all values are null, as seen in the ss.Expected behavior
Expected behavior is to get claims data in view component properly and constantly. For now this code is working on my computer, and same not working on my firend's.