如何返回json数据,然后停止自定义过滤器归因中的相应操作?

时间:2022-02-25 18:26:32

There is an asynchronous request that need authorize user. I want to authorize in filter attribution. If user can't login, return a json data that used to tell the client to callback a javascript function to popup the login window. how can I stop the action in filter attribution?

有一个需要授权用户的异步请求。我想在过滤器归因中进行授权。如果用户无法登录,则返回用于告诉客户端回调javascript函数以弹出登录窗口的json数据。如何在过滤器归因中停止操作?

1 个解决方案

#1


1  

Create a custom ActionFilterAttribute. Override OnActionExecuting.

创建自定义ActionFilterAttribute。覆盖OnActionExecuting。

public override void OnActionExecuting(ActionExecutingContext filterContext)
{
    if (!filterContext.HttpContext.User.Identity.IsAuthenticated)
    {
        filterContext.Result = new EmptyResult();
        return;
    }

    base.OnActionExecuting(filterContext);
}

Instead of EmptyResult return whatever you want.

而不是EmptyResult返回任何你想要的。

#1


1  

Create a custom ActionFilterAttribute. Override OnActionExecuting.

创建自定义ActionFilterAttribute。覆盖OnActionExecuting。

public override void OnActionExecuting(ActionExecutingContext filterContext)
{
    if (!filterContext.HttpContext.User.Identity.IsAuthenticated)
    {
        filterContext.Result = new EmptyResult();
        return;
    }

    base.OnActionExecuting(filterContext);
}

Instead of EmptyResult return whatever you want.

而不是EmptyResult返回任何你想要的。