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

编程入门 行业动态 更新时间:2024-10-18 21:18:10
本文介绍了如何从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结果?

本文发布于:2023-11-13 15:11:14,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1584670.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:Core   NET   ASP   API   Web

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!