ASP.NET membership check if a user is in a role in custom class

asp.net, vb.net

Solution

You need to reference System.Web in your business project. Then do the following:

    Dim context As System.Web.HttpContext = System.Web.HttpContext.Current
    Dim isRole As Boolean = context.User.IsInRole("Admin")

or c#

System.Web.HttpContext context = System.Web.HttpContext.Current;
bool isRole = context.User.IsInRole("Admin");

Problem

In my VS solution, I have two projects.One for the Web Interface, other for DataAcess and BusinessLogic. I know I can check if the currently logged-on user is Employee in Web Interface project like this from the code behind: ``` Dim isEmployee = User.IsInRole("Employee") ``` The problem is that I have a Class call UserManagement in my the DA and BL project which I want to check the currently logged-on user role also. I can't use `Dim isEmployee = User.IsInRole("Employee")` because it doesn't have aspx page. What do I need to do to check the user role in my custom class? Thank you.

Original source