有没有办法杀死过滤器内的HTTP请求。在以下代码中:
this.RequestFilters.Add((req, res, requestDto) =>
{
var access_token = req.Headers.GetValues("token");
if(access_token == null || String.IsNullOrEmpty(access_token[0]))
{
//Kill Request here, ensuring it does not hit the service and returns an unauthorized error code
}
答案 0 :(得分:3)
使用EndRequest()
结束请求并使请求管道短路,例如:
this.RequestFilters.Add((req, res, requestDto) =>
{
var access_token = req.Headers.GetValues("token");
if (access_token == null || String.IsNullOrEmpty(access_token[0]))
res.EndRequest()
}
答案 1 :(得分:1)
@rosdi是正确的,答案是执行以下操作:
this.RequestFilters.Add((req, res, requestDto) =>
{
var access_token = req.Headers.GetValues("token");
if(access_token == null || String.IsNullOrEmpty(access_token[0]))
{
throw new UnauthorizedAccessException();
}