0

I have a menu in web site. I want to access this for every role .

For example : i have 3 role that Role1 have access to personnel, referred, visit menu, and role2 have access to personnel, diet menu , and role3 have full access.

I created a static class that set value when user login in site. and use this class property for show/hide menu. but change this value when a nother user is login in site.

public static class GlobalVariables
{
    public static string UserName { get; set; }
    public static string Image { get; set; }

    public static bool IsAuthorizePersonnel { get; set; }
    public static bool IsAuthorizeReferred { get; set; }
    public static bool IsAuthorizeDiet { get; set; }
    public static bool IsAuthorizeVisit { get; set; }
 }

How do i set access for menu ?

abatishchev
  • 98,240
  • 88
  • 296
  • 433
ar.gorgin
  • 4,765
  • 12
  • 61
  • 100

2 Answers2

1

The static class is changing when new users login because ASP.NET handles multiple requests/clients in the same App domain, which means they share static classes/properties.

In order to make something like this work you would need to cache the information either via session state or a user keyed memory cache (such as Redis).

Alternatively, Asp.Net simple membership does have role support, so you could also consider creating the IsX properties as wrappers around role checks.

See the following articles for some examples:

Community
  • 1
  • 1
Travis
  • 689
  • 5
  • 11
  • Thanks, i use role and set user in role. but i want to get property value of user in login view and use this value in another view – ar.gorgin Apr 14 '15 at 04:35
0

Basically you have a single instance of the class which is used for all users in the site. Due to it being a static class.

You should create an instance-per-user class. Which you could place inside the cache under fi username.

souplex
  • 981
  • 6
  • 16