What the problem is?
We have an Exchange Server 2010 SP2, IIS 7.5 and a console app in VS2013.
So we have done the following:
TimeZoneInfo timeZone = TimeZoneInfo.Local;
ExchangeService EWSservice = new ExchangeService(ExchangeVersion.Exchange2010_SP2, timeZone);
//EWSservice.Url = new Uri("our url");
EWSservice.AutodiscoverUrl("my@mail.com", RedirectionUrlValidationCallback);
Both ways to define the url are working. Trying to set credentials:
EWSservice.Credentials = new WebCredentials("my@mail.com", "mypass");
This works too. But I want to connect by using the current Windows user credentials. Some code samples that had been used and crashed:
EWSservice.Credentials = new WebCredentials(CredentialCache.DefaultCredentials);
EWSservice.UseDefaultCredentials = true;
EWSservice.Credentials = (NetworkCredential)CredentialCache.DefaultCredentials;
All of this has returned a 401 error: Unauthorized
Additionally, I have edited the app.config like this - but it doesn't work:
<authentication mode="Windows">
</authentication>
<identity impersonate="false"/>
<!--Other stuff-->
</authentication>
Then, I have read about authentication modes and found this: Windows User getting "access denied" from exchange server
The admin has set this delegate option, but the connection is still not working...
Now I have added this:
EWSservice.TraceEnabled = true;
and I get an Exchange response in the console:
HTTP/1.1 401 Unauthorized
Content-Length: 0
Date: Wed, 20 Apr 2016 07:59:01 GMT
Set-Cookie: exchangecookie=bfab7cdda62a4bf8be5b43689199fcf6; expires=Thu, 20-Apr
-2017 07:59:02 GMT; path=/; HttpOnly
Server: Microsoft-IIS/7.5
WWW-Authenticate: Basic realm="our-domain"
X-Powered-By: ASP.NET
Any ideas?
I don't think your approach is possible but you may want to look at this ....
How to get the current user's Active Directory details in C#
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.