Seth
Seth

Reputation: 984

Converting Aspnet to aspnetcore: RequestContext.Principal

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

Answers (1)

crgolden
crgolden

Reputation: 4634

In ASP.NET Core, from within a controller this is done like:

var claimsPrincipal = User;

Reference: Migrate from ClaimsPrincipal.Current

Upvotes: 4

Related Questions