






















业务场景:
业务需求要求,需要对 WebApi 接口服务统一返回参数,也就是把实际的结果用一定的格式包裹起来,比如下面格式:
{
"response":{
"code":200,
"msg":"Remote service error",
"result":""
}
}
具体实现:
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Filters;
public class WebApiResultMiddleware : ActionFilterAttribute
{
public override void OnResultExecuting(ResultExecutingContext context)
{
Startup添加对应配置:
public void ConfigureServices(IServiceCollection services)
{
services.AddMvc(options =>
{
options.Filters.Add(typeof(WebApiResultMiddleware));
options.RespectBrowserAcceptHeader = true;
});
}
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。