Best way to abort/cancel action and response from ActionFilter

后端 未结 6 1648
清歌不尽
清歌不尽 2020-12-24 13:51

Best way to abort/cancel action from ActionFilter

I\'ve got this ActionFilter, and it\'s suppose to end the connection immediately and return a 401 Unau

6条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-12-24 14:29

    On .net core 2.2, 3.0 and 3.1, the below example works fine

    public override void OnActionExecuting(ActionExecutingContext context)
    {
      context.Result = new UnauthorizedObjectResult("user is unauthorized");
    }
    

提交回复
热议问题