【发布时间】:2016-10-23 18:52:30
【问题描述】:
我正在尝试编写一个中间件来防止某些客户端路由在服务器上被处理。我查看了很多自定义中间件类,它们会用
短路响应context.Response.End();
我没有在智能感知中看到 End() 方法。如何终止响应并停止执行 http 管道?提前致谢!
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
【问题讨论】:
-
只是不要打电话给
next()。
标签: c# middleware asp.net-core-1.0