'If-None-Match header always null in asp.net core controller
I send a request with "If-None-Match" header by postman, but it's always null in controller.
I'm using Asp.net core 1.1.
Is there anything wrong with my code?
if (Request.Headers.ContainsKey("If-None-Match"))
{
var oldETag = Request.Headers["If-None-Match"].First();
if (cache.Get($"Tenant-{id}-{oldETag}") != null)
{
return StatusCode((int)HttpStatusCode.NotModified);
}
}
UPDATE 1
I create a new request with both If-Match & If-None-Match header, but only If-Match header exists in controller If-None-Match still null.

Solution 1:[1]
You look into the wrong header in the debugger. Instead on
HeaderIfMatchcheckHeaderIfNoneMatchRequest.Headers.ContainsKey("If-None-Match")- this code is fine and works for me via Postman. But, accordingly to screenshot, looks like you addIf-None-Matchas a query parameter, not as a header.
Solution 2:[2]
Can you try this syntax?
request.Headers.Keys.Contains(HeaderNames.IfNoneMatch)
You can import HeaderNames from using Microsoft.Net.Http.Headers;
Solution 3:[3]
"If-None-Match" header is removed by "CSS Hot Reload" feature. You have to disable the hot reload in the Visual Studio options if you want to see the header while debugging.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | |
| Solution 2 | krishna |
| Solution 3 | palota |


