I am trying to fetch value of header from a request using this code
var headervalue= Request.Headers.GetValues("name")?.FirstOrDefault();
i thought this would also take care of the null value returned, as this might cause that issue
var headervalue= Request.Headers.GetValues("name").FirstOrDefault();
reason, is i want to avoid handling exception in case there is no header of specified key. in both above cases I get InvalidOperation Exception if header key is not found.
what is the best way to make this work without really having to handle invalidOp exception.
Update:
This particular syntax does not exist for me in my compiler
Request.Headers["name"] . hence GetValues() looks like my only option, which just throws invalidop exception if header isnt found.