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

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
    }
}
主站蜘蛛池模板: 新宁县| 西吉县| 临泽县| 长治县| 平谷区| 象州县| 闵行区| 太保市| 自贡市| 江西省| 乐都县| 青州市| 万宁市| 五河县| 武穴市| 惠安县| 保康县| 宁远县| 进贤县| 余江县| 宝清县| 昔阳县| 渭源县| 卓资县| 西乌珠穆沁旗| 蓝山县| 百色市| 禄丰县| 吴旗县| 古蔺县| 惠州市| 丹江口市| 永修县| 阜新市| 庆城县| 马关县| 渭源县| 枞阳县| 平遥县| 洪雅县| 洮南市|