Why is HttpContext Header Empty when trying to retrieve Header Information in MVC

Question: HttpContext Header is empty when attempt to retrieve data in C#, why is that?


Please Login to see the rest of the answer

Answer: There is a chance that you are trying to retrieve the Keys from the HttpContext Header in a wrong way. Keep in mind that HttpContext Header Keys shows differently when you step in the HttpContext using a Debugger, however, when actually quering the Values you need to drop the "Header" section. For Example:

 

var UserAgent = httpContext.Request.Header["HeaderUserAgent"] //This is wrong and will not yeld any results
var UserAgent = httpContext.Request.Header["User-Agent"] //This is right, will yeld results.

- Hope this helps you.


Write an Article
If you log in, you will be notified when someone leaves a comment.

Other users would like to know if this solution helped you.


© 2022 - ErnesTech - Privacy