Skip to main content
added 1 characters in body
Source Link
Olek
  • 686
  • 7
  • 11

The solution suggested by Richard is really beautiful, though as Matthieu noted someone might need extra html code to be rendered (or not rendered) as well. Thus Matthieu's solution seemseems to be more widely applicable, I would just centralize the logic regarding which users are considered admins in extension method.

Extension method:

public static bool IsAdmin(this WebViewPage page) { return page.User.IsInRole(@"Domain\ProjectAdmins"); } 

Usage:

@if (this.IsAdmin()) { <p> @Html.ActionLink("Create New Version", "Create") </p> } 

The solution suggested by Richard is really beautiful, though as Matthieu noted someone might need extra html code to be rendered (or not rendered) as well. Thus Matthieu's solution seem to be more widely applicable, I would just centralize the logic regarding which users are considered admins in extension method.

Extension method:

public static bool IsAdmin(this WebViewPage page) { return page.User.IsInRole(@"Domain\ProjectAdmins"); } 

Usage:

@if (this.IsAdmin()) { <p> @Html.ActionLink("Create New Version", "Create") </p> } 

The solution suggested by Richard is really beautiful, though as Matthieu noted someone might need extra html code to be rendered (or not rendered) as well. Thus Matthieu's solution seems to be more widely applicable, I would just centralize the logic regarding which users are considered admins in extension method.

Extension method:

public static bool IsAdmin(this WebViewPage page) { return page.User.IsInRole(@"Domain\ProjectAdmins"); } 

Usage:

@if (this.IsAdmin()) { <p> @Html.ActionLink("Create New Version", "Create") </p> } 
Source Link
Olek
  • 686
  • 7
  • 11

The solution suggested by Richard is really beautiful, though as Matthieu noted someone might need extra html code to be rendered (or not rendered) as well. Thus Matthieu's solution seem to be more widely applicable, I would just centralize the logic regarding which users are considered admins in extension method.

Extension method:

public static bool IsAdmin(this WebViewPage page) { return page.User.IsInRole(@"Domain\ProjectAdmins"); } 

Usage:

@if (this.IsAdmin()) { <p> @Html.ActionLink("Create New Version", "Create") </p> }