Tôi đang cố gắng viết một phần của phần mềm trung gian để giữ cho các tuyến đường khách hàng nhất định không được xử lý trên máy chủ. Tôi đã xem xét rất nhiều lớp middleware tùy chỉnh sẽ phản ứng ngắn vớiASP.NET Core Response.End()?
context.Response.End();
Tôi không thấy phương thức End() trong intellisense. Làm cách nào để chấm dứt phản hồi và ngừng thực hiện đường dẫn http? Cảm ơn trước!
public class IgnoreClientRoutes
{
private readonly RequestDelegate _next;
private List<string> _baseRoutes;
//base routes correcpond to Index actions of MVC controllers
public IgnoreClientRoutes(RequestDelegate next, List<string> baseRoutes)
{
_next = next;
_baseRoutes = baseRoutes;
}//ctor
public async Task Invoke(HttpContext context)
{
await Task.Run(() => {
var path = context.Request.Path;
foreach (var route in _baseRoutes)
{
Regex pattern = new Regex($"({route}).");
if(pattern.IsMatch(path))
{
//END RESPONSE HERE
}
}
});
await _next(context);
}//Invoke()
}//class IgnoreClientRoutes
Chỉ cần không gọi 'next()'. – SLaks