【发布时间】:2018-08-24 14:09:25
【问题描述】:
在 ASP.Net Core 2.0 中,我试图返回格式为 json 或 xml 的消息,并带有状态代码。我从控制器返回自定义消息没有问题,但我不知道如何在中间件中处理它。
到目前为止,我的中间件类看起来像这样:
public class HeaderValidation
{
private readonly RequestDelegate _next;
public HeaderValidation(RequestDelegate next)
{
_next = next;
}
public async Task Invoke(HttpContext httpContext)
{
// How to return a json or xml formatted custom message with a http status code?
await _next.Invoke(httpContext);
}
}
【问题讨论】:
-
请将有关标题的问题作为单独的
question发布在 SO 上。
标签: asp.net-core asp.net-core-2.0 asp.net-core-middleware request-pipeline