I am using RedirectToAction method of the base API controller. The first controller needs to modify the request headers (which I seem to be able to do) but the change is not retained.
This is a simplified implementation of what I am trying to do.
[HttpGet]
public IActionResult Get(string str)
{
// The request comes with a request header with key "Authorization" and value "ABC"
HttpContext.Request.Headers.Remove("Authorization");
HttpContext.Request.Headers.Add("Authorization", "XYZ");
return RedirectToAction("B");
}
[HttpGet]
public IActionResult B()
{
var value = HttpContext.Request.Headers.First(x => x.Key == "Authorization"); // I want this to be ""XYZ" , but it remains "ABC"
return Ok();
}
Any ideas on how I can get the second Action to use the Request header I updated in the first Action.
Edit:
All our Controllers / Actions are Authenticated using Core middleware JWT Auth Policy Only Action one allows Anonymous access. Action one is called from an internal related solution with a "Code" (Which is used to create a JWT token) . All other Actions require the JWT for Authentication.
The "Code" and JWT Token have independent expires and also hold some data.
The info in the "Code" is deemed more up to date. Action one can be called with both a "Code" and a JWT token.
The redirect was my way of flushing out old JWT token.
When action one is called with a valid "Code" a new JWT is created. I then want to redirect to a controller that will validate the JWT token (using middleware).
I know I can do this manually, but trying to trigger core middleware.