title: How design a controller action to respond to guess and authorized users
body: <p>I have an action in my controller design for users already register in my system:</p>
  
  <pre><code> [Authorize]
   public ActionResult getUserData()
   {
        string UserId = User.Identity.GetUserId();
        return getDataFromDB(UserID);
   }
  </code></pre>
  
  <p>And is working OK. Also redirect to the <code>LOGIN</code> page if you arent authenticated yet.</p>
  
  <p>But I also want to have a dummy function <code>getFakeData()</code> for anonymous users visiting the page so they can see the like a demo of the page.</p>
  
  <p>Where should I put the validation to see if user is authenticated or not and change the behaviour?</p>
  
  <ol>
  <li><p>On the webpage I can set the dataUrl based if user is authenticated. I can make a separated function without <code>[Authorize]</code> tag</p>
  
  <pre><code>@if (Request.IsAuthenticated)
  {
       dataUrl = '=/Project/Controller/getUserData'
  } else {
       dataUrl = '=/Project/Controller/getFakeData'    
  }
  </code></pre></li>
  <li><p>Or can I do it on the same action controller and checking if user is authenticated or not? But not sure is that is possible.</p></li>
  <li><p>Or is a better way to do it?</p></li>
  </ol>