Web Api 2 HttpContext or HttpActionContext

牧云@^-^@ 提交于 2020-01-02 02:32:06

问题


What is the difference between the following two ways of accessing the principle via an AuthorizeAttribute implementation?

Using HttpContext:

protected override bool IsAuthorized(HttpActionContext actionContext)
{
    return HttpContext.Current.User.IsInRole("DemoRole");
}

Using HttpActionContext:

protected override bool IsAuthorized(HttpActionContext actionContext)
{
    return actionContext.RequestContext.Principal.IsInRole("DemoRole");
}

来源:https://stackoverflow.com/questions/28235979/web-api-2-httpcontext-or-httpactioncontext

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