Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

User.IsInRole error

I have this code inside the Page_Load of the Site.Master.cs.

if(User.IsInRole("Read"))
{
   NavigationMenu.Visible = false;
}

and I get this error:

An object reference is required for the non-static field, method, or property 'Microsoft.VisualBasic.ApplicationServices.User.IsInRole(string).

Any clues?

like image 926
pikk Avatar asked Jun 05 '26 03:06

pikk


1 Answers

You can get current HttpContext user and validate for given role using IsInRole method as below.

HttpContext.Current.User.IsInRole("Read")

Change your method as

if(HttpContext.User.IsInRole("Read"))
{
   NavigationMenu.Visible = false;
}
like image 156
Damith Avatar answered Jun 07 '26 20:06

Damith