Asp.Net Web API passing user through layers

I use token authentication for my web API service. But I want to track the created, created data for all records. So I set HttpContext.Current.User and GenericIdentity with userId in my AuthenticationFilter . But I do not want to access the HttpContext from my datalayer, because I think the data layer should not know anything about the HttpContext .

So, are there any recommendations for passing user data through layers without an “HttpContext”?

+5
source share
1 answer

Assign your Principal to both HttpContxt.Current.User and Thread.CurrentPrincipal .

Then you can access Thread.CurrentPrincipal from anywhere in your code, of course, even from projects that don't have a link to System.Web .

+2
source

All Articles