How to handle authorization in the view layout

Posted by mathk on Stack Overflow See other posts from Stack Overflow or by mathk
Published on 2012-07-03T08:59:09Z Indexed on 2012/07/03 9:15 UTC
Read the original article Hit count: 231

Filed under:
|
|
|

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.

© Stack Overflow or respective owner

Related posts about c#

Related posts about asp.net-mvc-3