I've been returning HTTP status codes from within my ASP.NET Core web api as follows:
// Return code 200:
return Controller.Ok(someOptionalMessageHere);
I now have the need to return a status code 304 (i.e. not modified), but I don't see anything from intellisense in the "Microsoft.AspNetCore.Mvc.Controller" class that does that, nor do those namespaces appear in the online API browser (?). What is the proper way to do this?
As far as i know there is no explicit method for 304.
But you could use
return Controller.StatusCode(304,ObjectYouWantToReturn);
Edit: Here is a link to the documentation
As the eTag specification says you don't return content for a 304 (not modified) I suggest you do this instead:
return StatusCode((int)HttpStatusCode.NotModified);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With