How to handle authorization in the view layout
- by mathk
Authorize attribute are good to do some access control base on Action but suppose that I have some UI element in the layout that should note be output unless the user is authorize.
I could possibly set some boolean in the ViewBag but that is not the good solution I guess.
Somewhere in the Layout.cshtml:
@if (ViewBag.IsAuthorized)
{
<li>@Html.ActionLink("Index", "Admin")</li>
}
Let me know if there is a better solution.
Thanks.