I have an MVC app. It also uses services exposed by Web API controller.
Hosting environment for both MVC and Web API is IIS. In IIS authentication mode set is anonymous.
HttpModule is used to set User's identity and role to Thread and HttpContext object both.
Doing all that MVC controllers are being called properly but Web API controllers return 401 unauthorized error.
appropriate authorize attribute are used in both controllers.
Below is the code used user to set user to thread and context object.
var principal = new GenericPrincipal(new GenericIdentity(userName), roles);
// contextBase.User = principal;
HttpContext.Current.User = principal;
Thread.CurrentPrincipal = principal;