如何从ASP.NET Core Web API返回304结果?

问题描述:

我一直在从ASP.NET Core Web API中返回HTTP状态代码,如下所示:

I've been returning HTTP status codes from within my ASP.NET Core web api as follows:

// Return code 200:
return Controller.Ok(someOptionalMessageHere);

我现在需要返回状态码304(即未修改),但是在"Microsoft.AspNetCore.Mvc.Controller"类中,从intellisense中看不到任何东西,这些名称空间也没有出现在在线API浏览器(?)中.正确的方法是什么?

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?

据我所知,没有针对304的显式方法.

As far as i know there is no explicit method for 304.

但是您可以使用

return  Controller.StatusCode(304,ObjectYouWantToReturn);

这里是文档的链接