title: How to support NTLM authentication with fall-back to form in ASP.NET MVC?
body: <p>How can I implement following in ASP.NET MVC application:</p>
  
  <ol>
  <li>user opens intranet website</li>
  <li>user is silently authenticated if possible</li>
  <li>if NTLM authentication didn't worked out, show login form to user</li>
  <li>user indicate login password and select domain from list of predefined domains</li>
  <li>user is authenticated in code using AD</li>
  </ol>
  
  <p>I know how to implement 4 and 5 but cannot find info on how to combine NTLM and forms.
  So that NTLM native login/password dialog is never shown - transparent authentication or nice looking login page.</p>
  
  <p>How  should work?
  Should user be asked login and password? 
  Can her current credentials (domain username) be used without asking to enter login and password?</p>
  
  <p><strong>UPDATE for these, investigating same problem:</strong></p>
  
  <p>When I was asking this I was not fully understand how NTLM authentication works internally.
  Important thing here to understand is that if user's browser doesn't support NTLM properly or if NTLM support is disabled by user - server will never get chance to work around this.</p>
  
  <p>How Windows authentication is working:</p>
  
  <ol>
  <li>Client send a regular HTTP request to server </li>
  <li>Server responds with HTTP status 401 and indication that NTLM authentication must be used to access resources</li>
  <li>Client send NTLM Type1 message </li>
  <li>Server responds with NTLM Type2 message with challenge</li>
  <li>Client send Type3 message with response to challenge </li>
  <li>Server responds with actual content requested </li>
  </ol>
  
  <p>As you see, browser not supporting NTLM will not go to step (3), instead user will be shown IIS generated Error 401 page.</p>
  
  <p>If user doesn’t have credentials, after cancelling NTLM authentication popup dialog window browser will not continue to (3) as well.</p>
  
  <p>So we have no chance to automatically redirect users to custom login page.</p>
  
  <p>The only option here is to have a “gateway” page where we decide if user should support NTLM and if so, redirect to NTLM protected home page.</p>
  
  <p>And if not, show login form and allow authentication by manually entering login and password. </p>
  
  <p>Decision is usually made based on users’ IP address and/or host name either by matching IP ranges or by checking table of predefined IPs.</p>