in .net 4.6.2 we are using HttpContext like this
HttpContext.Current.Request.Headers.Add("language", languageCode);
But the same is faling in .net 5 and 6 What is the alternative for the above code.
in .net 4.6.2 we are using HttpContext like this
HttpContext.Current.Request.Headers.Add("language", languageCode);
But the same is faling in .net 5 and 6 What is the alternative for the above code.
I think the question has been answered here and here.
You can access the current request from the property HttpContext
from within a controller or inject IHttpContextAccessor
anywhere else in your code.
Add from client side:
var httpClient = new HttpClient() { BaseAddress = uri };
httpClient.DefaultRequestHeaders.Add("language", "en");