title: Windows Authentication WCF and ASP.Net MVC2: getting users AD info to a wcf webservice
body: <p>Hello there fellow StackOverflow and programming enthusiasts.  I have a question, I am trying to move an MVC website that I created over to a test server so that users can start testing... I have run into a little issue that I overlooked when I developed the site.  My website calls a service that I wrote that takes takes the service callers AD user name and uses it to do some back end work...</p>
  
  <pre><code>    private string CallerNameOnly = string.Empty;
      private string CallerFullDomain = string.Empty;
  
      public ACOService()
      {
          this.CallerFullDomain = OperationContext.Current.ServiceSecurityContext.WindowsIdentity.Name.ToString();
          this.CallerNameOnly = this.CallerFullDomain.Substring(this.CallerFullDomain.IndexOf('\\') + 1);
      }
  </code></pre>
  
  <p>This worked just perfectly when I was developing on my local machine and my username was passed into the service just fine...  However, I am having a hard time replicating the same functionality when I deploy to a server that I am using...  For some reason, the current user ends up being my machine name...
  Now, I seemed to have isolated the issue to a setting in IIS 7 that when changed, changes the behavior of my website somewhat...  If I go to the app pools advanced settings and I change the Process Model/Identity field, from LocalSystem, to any of the other Identity's It changes who the user is... My remote debugger kept bugging out on me so I couldn't figure out what the user name was, but you get the idea?<br>
  My question is, how do I get the username of the person using my website (which uses windows authentication) to call my web service with the username he used to access my site?  I thought about getting the username and passing it directly into a constructor ie...</p>
  
  <pre><code>    public ACOService(string userID)
      {
          this.CallerNameOnly = userID;       
      }
  </code></pre>
  
  <p>but that presents problems, because I already have a constructor with a string in it.  And I think I would have to place the constructor into my contract wouldn't I?  How would that work in WCF anyway?
  Any help with this problem would be greatly appreciated.</p>