What happened to filterContext.Cancel (ASP.NET MVC)

懵懂的女人 提交于 2019-12-12 10:32:30

问题


Before RC1 we did something like this:

public void OnAuthorization(AuthorizationContext filterContext)
    {
        if (whatever)
        {
            filterContext.Cancel();
        }
    }

This is gone now, how do we achieve the same results with RC1?

Thanks,

Kyle


回答1:


Instead of a Cancel property you just need to set the ActionResult to a different result. So for the Cancel property, you just have to replace your Cancel=true with

filterContext.Result = new HttpUnauthorizedResult();

REFERENCE

Breaking Changes for RC1:

AuthorizationContext - no longer has a Cancel property

UpdateModel - no longer accepts a FormCollection

UrlHelper - no longer accepts a ViewContext

Scotts Blog with the White Papers of RC1 changes.



来源:https://stackoverflow.com/questions/505653/what-happened-to-filtercontext-cancel-asp-net-mvc

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!