我能够重现该行为 -HttpContext
在单独的方法中使用单个参数移动处理程序会导致空响应:
WebApplicationBuilder builder = WebApplication.CreateBuilder();
WebApplication app = builder.Build();
app.Map("/Fails", Fails);
app.Map("/Fails1", Fails1);
app.Map("/Works", async (HttpContext c) =>
{
var response = await Task.Run(() => { return "response"; });
return response;
});
app.Map("/WorksToo", Works);
app.Map("/WorksToo1", Works1);
app.Map("/WorksToo2", Works2);
app.Run();
static async Task<string> Fails1(HttpContext context)
{
var response = await Task.FromResult("response");
return response;
}
public partial class Program
{
internal static async Task<string> Fails(HttpContext context) => await Task.FromResult("response");
internal static async Task<string> Works(HttpContext context, string someParam) => await Task.FromResult("response");
internal static async Task<string> Works1(HttpContext context, ILogger<Program> _) => await Task.FromResult("response");
internal static async Task<string> Works2(HttpRequest context) => await Task.FromResult("response");
}
在github上发布了新问题。现在,您可以像我一样将虚拟参数添加到处理程序Works1
。