.ConfigureApiBehaviorOptions(setupAction =>
{
setupAction.InvalidModelStateResponseFactory = context =>
{
ValidationProblemDetails details = new ValidationProblemDetails(context.ModelState)
{
Type = "",
Title = "数据验证失败",
Status = StatusCodes.Status422UnprocessableEntity,
Detail = "请看详细说明",
Instance = context.HttpContext.Request.Path
};
details.Extensions.Add("traceId", context.HttpContext.TraceIdentifier);
return new UnprocessableEntityObjectResult(details){ ContentTypes = { "application/json" } };
};
});
. Net Core实战+RESTful思想纵深课程,开发优雅RESTful风格API。
了解课程