I have implemented a custom AuthorizationFilter in my ASP.NET Core Web API. The filter checks for a code in the request header and identifies the userID based on the code.
I want this userID to be reused in my GET/POST call. How can I transfer data from my AuthorizationFilter to my calling method to avoid duplicate database calls?
AuthorizationFilter function:
public void OnAuthorization(AuthorizationFilterContext context)
{
string header = _httpContextAccessor.HttpContext.Request.Headers["CODE"].ToString();
int userID = GetAccessData(header);
//Want to use this UserID in my calling method
}
Calling function in my controller:
[HttpGet]
public IActionResult UseData(Model modelObj)
{
// I want to use userID retrieved at filter level here.
}
