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

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
    }
}
主站蜘蛛池模板: 民权县| 临夏市| 甘谷县| 昌图县| 海淀区| 巩留县| 郧西县| 千阳县| 大方县| 麻城市| 台东市| 湖北省| 台北市| 滕州市| 贡觉县| 繁昌县| 渭源县| 内乡县| 秦皇岛市| 洪雅县| 睢宁县| 巫溪县| 新安县| 青海省| 湟中县| 那曲县| 基隆市| 新竹市| 朝阳区| 崇信县| 年辖:市辖区| 蒙山县| 余庆县| 武安市| 青浦区| 涞水县| 石屏县| 上虞市| 新沂市| 托里县| 潜江市|