【发布时间】:2016-03-30 14:57:08
【问题描述】:
我需要对请求应用过滤器。我创建了一个ActionFilterAttribute 的子类,并覆盖了OnActionExecutionAsync(ActionExecutingContext context, ActionExecutionDelegate next)。我在过滤器中有一些复杂的逻辑,在某些情况下,我必须停止过滤器的运行并返回默认操作结果(就像没有过滤器一样)。如果我在过滤器中return,工作流似乎完全停止,没有操作结果返回。我尝试await next() 或致电base.OnActionExecutionAsync(...),但没有成功。如何实现从过滤器返回?
我有这样的事情:
public override async Task OnActionExecutionAsync(ActionExecutingContext context, ActionExecutionDelegate next)
{
//some logic
if (questionnaireId == Guid.Empty)
{
//here I need to let the mvc action run normally
return;//it doesn't work
} else {
//some logic..
}
}
【问题讨论】:
-
你能发布你的代码吗?还有为什么要实现一个
ActionFilter,可能一个middleware是最好的选择 -
@aguafrommars 我怀疑中间件,因为我的逻辑只处理 MVC,我不想在整个应用程序的管道中再添加一个处理程序
标签: asp.net-core actionfilterattribute