I have been tasked with writing a .NET application that has to have access to a users exchange calendar. This application will only be accessed from the local network and I need to have to automatically use the current domain users credentials to access exchange.
I have the following code but I get an error saying "The account does not have permission to impersonate the requested user."
ExchangeService service = new ExchangeService();
service.UseDefaultCredentials = true;
string exchange = "exchangeWSURL";
service.Url = new Uri(exchange);
service.ImpersonatedUserId = new ImpersonatedUserId(ConnectingIdType.PrincipalName, userid);
service.PreAuthenticate = true;
CalendarView cal = new CalendarView(startDate, startDate.AddDays(7));
FindItemsResults<Appointment> findResults = service.FindAppointments(WellKnownFolderName.Calendar, cal);
It looks like I am doing something wrong. I was hoping to now have to turn on impersonation for all users on the domain.
Any help would be wonderful.