3

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?

Community
  • 1
  • 1
  • So is the console App failing or are you trying to do this in ASP.net ? You might want to look at some request in fiddler and have a look at what Authentication headers its trying to use (eg Basic or NTLM). This is old but given the EWS Managed API still uses the Httpwebrequest still relative https://blogs.msdn.microsoft.com/buckh/2004/07/28/authentication-in-web-services-with-httpwebrequest/ – Glen Scales Apr 20 '16 at 05:40
  • Its occuring in console App. Using HttpWebRequest return 401 error too – Айнур Васбиев Apr 20 '16 at 09:58

1 Answers1

0

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#

Community
  • 1
  • 1
rojobo
  • 476
  • 4
  • 16
  • And what kind of detail i'l get from AD? user mail is already known – Айнур Васбиев Apr 20 '16 at 06:05
  • Your question is: how to get the current user credentials am I mistaken? If you already have the current user mail then I think you are approaching the problem the wrong way. You need a SINGLE account credentials with permission to impersonate other accounts https://msdn.microsoft.com/en-us/library/office/dd633680(v=exchg.80).aspx By doing this youll only have to have ONE username and password and then if you wan to access someone else's mailbox all you need is the mail – rojobo Apr 20 '16 at 12:54