Skip to content

Thread.CurrentPrincipal is not persisted in .Net Core 3.1 #35947

@andreyciocan

Description

@andreyciocan

Hello!

I am having an issue with Thread.CurrentPrincipal after migrating from .Net Core 2.2 to .Net Core 3.1

I am setting my Thread.CurrentPrincipal in a Custom Authorization Handler like this:
`
var claims = new List {
new Claim("CustomIdClaim", <user_id>),
new Claim(ClaimTypes.Name, <user_name>)
};

        Thread.CurrentPrincipal = new ClaimsPrincipal(new ClaimsIdentity(claims)); 

`
and then I am trying to get Thread.CurrentPrincipal in a static method initialized in Startup class like this:

var principal = (ClaimsPrincipal)Thread.CurrentPrincipal;
.

The problem is that in the static method, Thread.CurrentPrincipal is always null. I must mention that my custom authorization handler is called before the static method on every request.

This worked just fine with .Net Core 2.2.

Thanks in advance!

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions