title: AD User Authentication
body: <p>I am attempting to create an ASP.NET (.NET 3.5) website to connect to our Exchange 2010 server through Exchange Web Services, I am able to connect to EWS when I define the username, password and domain to authenticate with but I would like, if possible, to not include login details in my code.</p>
  
  <p>In IIS I have enabled Integrated Windows Authentication for the site, in web.config of the site I have <code>&lt;authentication mode="Windows"/&gt;</code>.</p>
  
  <p>The following code is what I have been woking with:</p>
  
  <pre><code>svc.UseDefaultCredentials = True
  svc.Credentials = New WebCredentials()
  svc.Url = New Uri(svcURL)
  </code></pre>
  
  <p>With the above code I am receiving the message:</p>
  
  <blockquote>
    <p>When making a request as an account that does not have a mailbox, you
    must specify the mailbox primary SMTP address for any distinguished
    folder Ids.</p>
  </blockquote>
  
  <p>When I attempt to use <code>svc.Credentials = CredentialCache.DefaultNetworkCredentials</code> (in place of <code>svc.Credentials = New WebCredentials()</code>) I receive the error message:</p>
  
  <blockquote>
    <p>Unable to cast object of type 'System.Net.SystemNetworkCredential' to
    type 'Microsoft.Exchange.WebServices.Data.ExchangeCredentials'.</p>
  </blockquote>
  
  <p>As mentioned, the only thing that has worked is to define the user credentials to authenticate to by hardcoding user login details, which I would rather not do: <code>svc.Credentials = New WebCredentials("username","password","domain")</code></p>
  
  <p>Has anyone been able to authenticate to EWS using the credentials of the current logged in user in an ASP.NET website?</p>