title: How to restrict access to certain actions in controller in ASP.net MVC
body: <p>I am new to ASP.net MVC and created my first web application using it. In my application I am using database authentication. I have created Login action in controller which checks entered username and password exist in DB or not, If it exist then put required values in Session and redirect user to pages as per his rights else redirect user to login page. Like this</p>
  
  <pre><code>public ActionResult Login()
  {
     if(uservalid)
     {
        //set session values and redirect to dashboard
     }
     else
     {
        //redirect to login
     }
  }
  </code></pre>
  
  <p>In my application there are some functionality that can only be accessed when user is logged-in. I want to check whether user is logged-in or not before user try to access these functionality and if he is not logged-in or not have rights then redirect to login page or show some error message.</p>
  
  <pre><code>public ActionResult SomeAction()
  {
     //Available only when user is logged-in
  }
  </code></pre>
  
  <p>So how do I check whether user is logged-in or not and give access to action. I read about Authorize attribute but don't know how to use it as I am using database authentication.</p>