0

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.

Etienne de Martel
  • 34,692
  • 8
  • 91
  • 111
shu
  • 1,938
  • 10
  • 19

2 Answers2

1

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.

0

Add from client side:

var httpClient = new HttpClient() { BaseAddress = uri };

httpClient.DefaultRequestHeaders.Add("language", "en");
Serve Laurijssen
  • 9,266
  • 5
  • 45
  • 98