If-None-Match header always null in asp.net core controller

Viewed 1281

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?

enter image description here Debug enter image description here 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. enter image description here enter image description here

3 Answers

Can you try this syntax? request.Headers.Keys.Contains(HeaderNames.IfNoneMatch)

You can import HeaderNames from using Microsoft.Net.Http.Headers;

"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.

Related