如何从ASP.NET Core Web API返回304结果? [英] How to return a 304 result from ASP.NET Core web api?

查看:141
本文介绍了如何从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);

这里是文档的链接

这篇关于如何从ASP.NET Core Web API返回304结果?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆