title: Checking logged in user role in View in ASP.NET Core 2.2
body: <p>A user in my web application may have several roles coming from different applications. Those roles are stored in the <code>HttpContext</code> in an array that is Serialized called Roles.</p>
  
  <p><a href="https://i.stack.imgur.com/MEKqN.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/MEKqN.png" alt="enter image description here"></a></p>
  
  <p>Currently for my controller I implement a custom filter that deserializes the array and reads the items within like this </p>
  
  <pre><code>public void OnActionExecuting(ActionExecutingContext context)
  {
              string[] applications = ListOfApplications.Split(",");
              string[] roles = ListOfRoles.Split(",");
              var userRoles = context.HttpContext.User.Claims.Where(c =&gt; c.Type == "Roles").Select(c =&gt; c.Value).ToList();
              var matches = 0;
              foreach (var item in userRoles)
              {
                  var currentItem = JsonConvert.DeserializeObject&lt;UserRoleDetailsViewModel&gt;(item);
                  UserRoleDetailsViewModel urdvm = new UserRoleDetailsViewModel
                  {
                      Id = currentItem.Id,
                      Name = currentItem.Name,
                      ApplicationId = currentItem.ApplicationId,
                      ApplicationName = currentItem.ApplicationName
                  };
                  for (var i = 0; i &lt; applications.Length; i++)
                  {
                      if(applications[i] == ApplicationGlobals.All &amp;&amp; roles[i] == RoleGlobals.All)
                      {
                          matches++;
                      }
                      if(applications[i]== ApplicationGlobals.All &amp;&amp; roles[i] == urdvm.Name)
                      {
                          matches++;
                      }
                      if(applications[i] == urdvm.ApplicationName &amp;&amp; roles[i] == urdvm.Name)
                      {
                          matches++;
                      }
                  }
              }
              if (matches == 0)
              {
                  context.Result = new RedirectToActionResult("Index", "Home", null);
              }
  }
  </code></pre>
  
  <p>And I call it on top of my controller like this:</p>
  
  <pre><code>[Authorize]
  [TypeFilter(typeof(ValidateRolesFilter), Arguments = new object[] {
          ApplicationGlobals.app1+","+ApplicationGlobals.app1
          ,RoleGlobals.SystemAdministrator+","+RoleGlobals.User
  })]
  </code></pre>
  
  <p>However, this only works until the controller. How can I extend this to work in a view so that I am able to segment off areas in the navigation bar for example based on the users role? Is this possible?</p>