【发布时间】:2021-03-13 10:13:45
【问题描述】:
我有一个 asp.net 核心中间件,它应该记录一些请求内容,然后返回一个图像。
在中间件响应中,我喜欢将图像作为字节 [] 返回。我玩弄了 context.Reponse.WriteAsync() 对象,但没有找到任何返回图像的解决方案。
public class TrackerMiddleware
{
private readonly IClientInformationManager _clientInformationManager;
private readonly RequestDelegate _next;
public TrackerMiddleware(RequestDelegate next, IClientInformationManager clientInformationManager)
{
_next = next;
_clientInformationManager = clientInformationManager;
}
public async Task Invoke(HttpContext context)
{
var clientInfo = new ClientInformationLogDTO();
clientInfo.AgentContext = context.Request.Headers["User-Agent"];
await _clientInformationManager.CreateLogAsync(clientInfo);
//TODO: Return image here
await context.Response.WriteAsync("");
//await _next(context);
}
}
如何修改我的中间件以返回图像?
【问题讨论】:
标签: response middleware