0

I have a MVC5 Razor website that needs to show calendar appointments loaded from excahnge server.

I can do this by doing this:

var service = new ExchangeService { Credentials = new NetworkCredential("userName", "pass") };
service.AutodiscoverUrl("me@workplace.com");

var calendar = CalendarFolder.Bind(service, WellKnownFolderName.Calendar, new PropertySet());
var cView = new CalendarView(DateTime.Today, DateTime.Today.AddMonths(1));
cView.PropertySet = new PropertySet(ItemSchema.Subject, AppointmentSchema.Start, AppointmentSchema.End, AppointmentSchema.Organizer);
var result = calendar.FindAppointments(cView);

But insted of the hardcoded credentials, I need the credentials (and from that I can get the email) of the current users Windows User. I also need to get appointments from a calender that is shared with that user, and not the users own calendar (but that is perhaps a seperate question).

Nothing I have tried works. Would love some help!

Other code:

private static bool RedirectionUrlValidationCallback(string redirectionUrl)
{
    var result = false;
    var redirectionUri = new Uri(redirectionUrl);
    if (redirectionUri.Scheme == "https")
    {
        result = true;
    }
    return result;
}
Niksen
  • 79
  • 1
  • 11
  • https://msdn.microsoft.com/en-us/library/system.net.credentialcache.defaultnetworkcredentials(v=vs.110).aspx – ADyson Mar 07 '18 at 14:24
  • @ADyson - This does work locally, but not when published to the server. – Niksen Mar 07 '18 at 14:40
  • 1
    Possibly you need to enable impersonation, and/or Kerberos delegation. – ADyson Mar 07 '18 at 15:07
  • Enable impersonation is turned on on the server, but it still does not work. – Niksen Mar 13 '18 at 12:59
  • Sorry for spamming, but CredentialCache.DefaultNetworkCredentials returns an object with all propertys as empty strings. Anyone know why? – Niksen Mar 13 '18 at 13:29
  • That's normal, you can't read the windows network credentials of the user, they're secret. All you've got is a signed token. Don't take that as an indication of a problem. What about Kerberos delegation, did you try that? – ADyson Mar 13 '18 at 16:30

0 Answers0