If-None-Match header is always null in asp.net core controller
I send a request with an "If-None-Match" header in a post, but it's always null
in the controller.
I am using Asp.net core 1.1.
Is there something 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 headers If-Match
and If-None-Match
, but only the header If-Match
exists in the controller If-None-Match
yet null
.
source to share
-
You are viewing the wrong header in the debugger. Instead,
HeaderIfMatch
checkHeaderIfNoneMatch
-
Request.Headers.ContainsKey("If-None-Match")
- this code is ok and works for me via Postman. But, as per the screenshot, it looks like you are addingIf-None-Match
as a request parameter and not as a header.
source to share