title: Authorize user programatically in asp.net mvc
body: <p>I need to authorize users programatically.</p>
  
  <p>I have the authorize attribute around my controller:</p>
  
  <pre><code>  [Authorize]
    public class ProductsController : Controller
  </code></pre>
  
  <p>In another controller action, I'm invoking a webservice which returns an account number if successful. If not, it will return an error. Basically if the if condition is true I want to authorize user across the rest of the site.</p>
  
  <pre><code> if (!string.IsNullOrEmpty(response.AccountNumber))
   {
     //Write code to Authorize user to use the rest of the site...
     then redirect to a page on my site.
   }else
   {
    //not authorized,
   }
  </code></pre>
  
  <p>The users of the site will be admins.</p>
  
  <p>Thanks</p>