Chris
Chris

Reputation: 1900

Thread.CurrentPrincipal is Reset/ClaimsPrincipal Lost when retrieving from ClaimsPrincipal.Current

I am have a WinForms App running .Net 4.5.2.

When logging in, I create a ClaimsPrincipal with a bunch of claims. I save to the Thread.CurrentPrincipal. In the same logging-in process, the ClaimsPrincipal works fine.

After the application initializes, when the user clicks on a control, I try to retrieve the ClaimsPrincipal from ClaimsPrincipal.Current. When I do, it is a GenericPrincipal and it loses all its claims.

What am I doing wrong?

Upvotes: 0

Views: 599

Answers (1)

Chris
Chris

Reputation: 1900

It seems this is an issue with WinForms and .Net 4.5.2. Microsoft did say they were going to stop supporting WinForms.

What I found in this case is that if you call ClaimsPrincipal.Current before you set it through Thread.CurrentPrincipal... you run into trouble.

Either the static object gets set to a default GenericPrincipal or the Thread.CurrentPrincipal gets reset.

Whatever the reason the instability is there.

Upvotes: 1

Related Questions