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

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
    }
}
主站蜘蛛池模板: 山阳县| 车致| 罗平县| 名山县| 城步| 蚌埠市| 济南市| 仁布县| 文昌市| 东兰县| 大姚县| 龙里县| 思茅市| 怀宁县| 乌兰浩特市| 五峰| 新昌县| 女性| 芮城县| 翁源县| 望都县| 会昌县| 额尔古纳市| 城口县| 慈溪市| 新昌县| 同德县| 栾城县| 西和县| 蓬溪县| 海丰县| 商水县| 荆州市| 宣武区| 含山县| 东阿县| 沈阳市| 永平县| 宁乡县| 武定县| 黄陵县|