官术网_书友最值得收藏!

Authorization inside a controller action

Sometimes, it may be required to change the behavior after processing the request based on the principal. In such scenarios, we can implement authorization in a controller action. For example, if you would like to manipulate the response based on the user's role, we can verify the logged-in user role from the ApiController.User property in the action method itself:

public HttpResponseMessage Get()
{
    if (!User.IsInRole("Admin"))
    {
        // manipulate the response to eliminate information that shouldn't be shared with non admin users
    }
}
主站蜘蛛池模板: 儋州市| 芒康县| 镇坪县| 贺州市| 洛南县| 屯昌县| 页游| 锦屏县| 蒙自县| 岱山县| 尉氏县| 洪洞县| 富顺县| 广饶县| 大渡口区| 琼中| 香格里拉县| 开封县| 垣曲县| 吉隆县| 高邮市| 丹棱县| 鄱阳县| 桓仁| 朔州市| 石河子市| 贡嘎县| 公安县| 金堂县| 靖安县| 勃利县| 贵定县| 道孚县| 通榆县| 宜州市| 界首市| 昌都县| 克山县| 河间市| 上犹县| 获嘉县|