title: ASP.Net MVC 5 Check User Role For _Layout
body: <p>Hello everyone I am trying to check what Role my user is in with the default setup.
  I thought I would only need 'User.IsInRole("User")' for in my View but its not so easy.
  I want to display certain links depending on the role for the user.
  Here is what I have and I tried a few different options.
  I have the default setup database and some added tables that dont matter for this part.
  Request.IsAuthenticated works for login.</p>
  
  <p>I tried user.isinrole and request.isauthenticated but nether worked for this instance with my view</p>
  
  <pre><code>@if (Request.IsAuthenticated)
                      {
                          &lt;li class="nav-item"&gt;
                              &lt;a class="nav-link" href="#"&gt;Assign Roles&lt;/a&gt;
                          &lt;/li&gt;
                          &lt;li class="nav-item"&gt;
                              &lt;a class="nav-link" href="#"&gt;View Roles&lt;/a&gt;
                          &lt;/li&gt;                        
                          &lt;li class="nav-item"&gt;
                              &lt;a class="nav-link" href="#"&gt;Reset Password&lt;/a&gt;
                          &lt;/li&gt;
                      } else if (Request.IsAuthenticated &amp;&amp; User.IsInRole("User"))
                      {
                          &lt;li class="nav-item"&gt;
                              &lt;a class="nav-link" href="#"&gt;user Else clause&lt;/a&gt;
                          &lt;/li&gt;
                      } else if (Request.IsAuthenticated &amp;&amp; User.IsInRole("Guest"))
                      {
                          &lt;li class="nav-item"&gt;
                              &lt;a class="nav-link" href="#"&gt;guest Else clause&lt;/a&gt;
                          &lt;/li&gt;
                      } else
                      {
                          &lt;li class="nav-item"&gt;
                              &lt;a class="nav-link" href="#"&gt;else else!! Else clause&lt;/a&gt;
                          &lt;/li&gt;
                      }
  </code></pre>
  
  <p>The 'else' works when no user is logged in. </p>