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?

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 headers If-Match

and If-None-Match

, but only the header If-Match

exists in the controller If-None-Match

yet null

. enter image description here enter image description here

+3


source to share


1 answer


  • 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 adding If-None-Match

    as a request parameter and not as a header.



0


source







All Articles