title: ASP.NET MVC - HTTP Authentication Prompt
body: <p>Is it possible to make my application ask for username and password prompting for it before render a view?
  Just like on twitter API to get information about your account:</p>
  
  <p><a href="http://twitter.com/account/verify_credentials.xml" rel="noreferrer">http://twitter.com/account/verify_credentials.xml</a></p>
  
  <p>So before render the view || file it asks you to insert you username and password, I think this is made directly on the server since the curl request is based on username:password as well like this:</p>
  
  <pre><code>curl -u user:password http://twitter.com/account/verify_credentials.xml
  </code></pre>
  
  <p>As I'm trying to build an API following the same structure I would like to know how I can do this on ASP.NET MVC C#. I've already used this on ruby rails and its pretty simple like:</p>
  
  <pre><code>before_filter :authenticate
  
  def authenticate
      authenticate_or_request_with_http_basic do |username, password|
      username == "foo" &amp;&amp; password == "bar"
  end
  </code></pre>
  
  <p>I don't think that [Authorize] filter is the same since I believe it's just a redirection,
  and it redirects you to the Accounts Internal Controller that is based on the accounts database, in this case I will use another database, specifically from a webservice and do the validation after the information is submitted.
  But I need the action to require the user and pass credentials on its request.</p>
  
  <p>Thanks in advance</p>
  
  <hr>
  
  <p>UPDATE:</p>
  
  <p>Actually to request a page that requires this authentication (i.e. Twitter)
  I would have to declare this on its request</p>
  
  <pre><code>request.Credentials = new NetworkCredential("username", "password");
  </code></pre>
  
  <p>And this would reflect that prompted username and password.</p>
  
  <p>So, it's exactly the same thing but from the other side, if it's possible to <b>provide</b> information to the  authentication prompt on request, how could I <b>require</b> this authentication on the request instead?</p>
  
  <p>So everytime somebody tries to make a request to my application on example:</p>
  
  <p><a href="http://myapplication/clients/verify_credentials" rel="noreferrer">http://myapplication/clients/verify_credentials</a></p>
  
  <p>it should ask for a username and password with that server prompt
  so to retrive information on curl for example it would be like this</p>
  
  <pre><code>curl -u user:password http://myapplication/clients/verify_credentials
  </code></pre>