title: Checking login user role in razor page
body: <pre><code>@if (Request.IsAuthenticated &amp;&amp; User.Identity.Name=="administrator")
  {
       &lt;div id="sidebar"&gt;
          &lt;div class="module"&gt;
          &lt;ul class="menu"&gt;
                              &lt;li&gt;@Html.ActionLink("Home", "Index", "Home")&lt;/li&gt;
                              &lt;li&gt;@Html.ActionLink("About", "About", "Home")&lt;/li&gt;
                              &lt;li&gt;@Html.ActionLink("Contact", "Contact", "Home")&lt;/li&gt;
                          &lt;/ul&gt;
           &lt;/div&gt;
           &lt;div class="mainContent"&gt;
               Hello, @User.Identity.Name !
           &lt;/div&gt;
       &lt;/div&gt;
  </code></pre>
  
  <p>This is my layout if the user is authenticated as administrator but this sort of check looks no good, I need to check the role of the user not his name.</p>
  
  <p>Here is the controler method </p>
  
  <pre><code>    public ActionResult AuthenticatedUserLayout(string username) 
      {
          var lst=userContext.UserProfiles.ToList();
          var user = lst.Select(u =&gt; u.UserName == username);
  
          if(IsAdmin(Session["LoginUser"].ToString())) return View(user); else return Index();
      }
  </code></pre>
  
  <p>I also find that <code>return View(user)</code> is no good, because I don't know how to make any use of that <code>user</code>. </p>