title: ASP.Net MVC 3 Login and Windows Authentication
body: <p>I am working on an ASP.Net MVC 3 application and I am having a User table that stores usernames and their passwords. I have created an additional ADUsername (stores Active Directory's Domain/Username).</p>
  
  <p>I am trying to do the following:</p>
  
  <ol>
  <li><p>Users running the application from Intranet should not see login page. Their Domain/Username should be received automatically and compared against ADUsername field.</p></li>
  <li><p>Users running the application from internet (out of the local network) or users with no ADUsername value: should see the login screen and they should use my custom Username and Password fields to login.</p></li>
  </ol>
  
  <p>This was very easy using Visual Studio Development Server and very difficult using IIS :)</p>
  
  <p>As I set my Web.Config to use forms, I am using WindowsIdentity.GetCurrent().Name to get the current ADUsername and then, I lookup my User table to find the user and FormsAuthentication.SetAuthCookie him.</p>
  
  <p>Using IIS is always returning APPPOOL\ASP.NET v4.0 user which is not reflecting the domain/user I needed.</p>
  
  <p>Any Help?</p>