Reputation: 984
Ok, so I'm working on converting a webApi from aspnet to aspnetcore.
I have the following inside of an HTTP post.
var name = ControllerContext.RequestContext.Principal.Identity.Name;
widget.CreatedBy = name;
//Other properties
DataContext.Widgets.Add(entity);
The problem I'm running into is that RequestContext
doesn't seem to exist in aspnetcore
. I've been searching for the better part of a day for an equivalence.
Upvotes: 2
Views: 3135
Reputation: 4634
In ASP.NET Core, from within a controller this is done like:
var claimsPrincipal = User;
Reference: Migrate from ClaimsPrincipal.Current
Upvotes: 4