mercredi 21 juillet 2010

User/role extension methods in an ASP.NET MVC view

This is a small Html helper that I use when I need to check the role in a view

public static class PageHelper
public static bool IsAdmin(this ViewUserControl pg)
return pg.Page.User.IsInRole("Admin");

public static bool IsCustomer(this ViewUserControl pg)
return pg.Page.User.IsInRole("Customer");
Don't forget to add the namespace for your extension methods in your Web.config :
<add namespace="MyProject.Web.Helpers" />

Aucun commentaire:

Enregistrer un commentaire