title: MVC3 Forms Authentication: Role Specific Visible Items in Partial View
body: <p>I just set up my MVC application with forms authentication and everything is just dandy except for my <code>_LogOnPartial</code> view. The "Welcome  [Log Off]" works fine, however, I also have Role specific text or drop-down selector that needs to be displayed depending on the user's role.</p>
  
  <p>This works fine as long as the user has logged in during the current session because I use cookies to hold the role and verify with <code>User.IsInRole()</code> in the Controller before any actions occur.</p>
  
  <p>This does not work if the user selects "Remember me" because when the session starts, there is no cookie containing the role, and thus the visible items.</p>
  
  <p>Is there an easy way to check <code>User.IsInRole()</code>in a partial view?</p>
  
  <p>Here is my View:</p>
  
  <pre><code>&lt;div id="LogInContainer"&gt;
      @if (Request.IsAuthenticated)
      {
          &lt;div class="InLine" id="WelcomeDisplay"&gt;
              &lt;text&gt;Welcome &lt;b&gt;@Context.User.Identity.Name&lt;/b&gt;! [ @Html.ActionLink("Log Off", "LogOff", "Account")
              ]
              &lt;/text&gt;
          &lt;/div&gt;
          &lt;div id="clientDropDown"&gt;
              @{
  
          var requestCookie = Request.Cookies["Role"];
          if (requestCookie != null)
          {
              if (requestCookie.Value == "Client1")
              {
                  HttpCookie joannCookie = new HttpCookie("Client", "Client1");
                  Response.Cookies.Add(Client1Cookie);
                  &lt;text&gt;Client: Client1&lt;/text&gt;
              }
              else if (requestCookie.Value == "Client2")
              {
                  HttpCookie safewayCookie = new HttpCookie("Client", "Client2");
                  Response.Cookies.Add(Client2Cookie); 
                  &lt;text&gt;Client: Client2&lt;/text&gt;
              }
              else if (requestCookie.Value == "Administrator")
              {
                  @:Client: @Html.DropDownList("Client", new SelectList(ConfigurationHelper.Clients))
                  }
          }
          else
          {
              //Do nothing
          }
              }
          &lt;/div&gt;
      }
      else
      {
          &lt;div id="LogOnLink"&gt;
              [ @Html.ActionLink("Log On", "LogOn", "Account") ]
          &lt;/div&gt;
      }
  &lt;/div&gt;
  </code></pre>
  
  <p>Is there a way to make nonauth cookies persistent? I'm new to cookies so I may just be ignorant, but I tried a google search with no luck.</p>