Tom Robinson
Tom Robinson

Reputation: 8508

What has changed in the AuthorizeAttribute in ASP.NET Web API 2?

I have upgraded a project and set of unit tests from ASP.NET Web API to ASP.NET Web API 2.

We are using a custom DelegatingHandler for a custom authentication mechanism.

It sets the Thread.CurrentPrincipal and HttpContext.Current.User to the appropriate System.Security.Claims.ClaimsPrincipal.

Since upgrading to ASP.NET Web API 2, with no other code changes, the web hosted version works fine but the unit tests fail. They worked before the upgrade.

Does ASP.NET Web API 2 now require the principal to be set in the HttpContext?

Upvotes: 2

Views: 1100

Answers (1)

In web API 2, you will need to call GetRequestContext() on the request object and set the Principal property to your claims principal.

Go to http://aspnetwebstack.codeplex.com/workitem/1294 and find "davidmatson wrote Sep 13 at 10:18 PM".

Upvotes: 6

Related Questions