Reputation: 2421
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.
Upvotes: 3
Views: 6290
Reputation: 1732
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");
Upvotes: 4
Reputation: 233
In your web application, when you initially determine the role(s) for a user, that code should be calling business objects of some sort that make the determination. So the dependency is from your web app to your business layer (i.e. your web app requires your business layer), not the other way around.
Upvotes: 0