Alexander
Alexander

Reputation: 1061

Add Appointment to Exchange Calendar from ASP.NET MVC Intranet Application

I have got an ASP.NET MVC 4 Intranet Application.

The application uses the windows authentication for authenticating users. I can get the Username with User.Identity.Name. This contain the domain name and username (MyDomain\Username).

I now want to add an appointment to the users calender via the Exchange Web Service API.

I can do this like the following:

var service = new ExchangeService(ExchangeVersion.Exchange2010_SP2);
        service.Credentials = new WebCredentials(Settings.MyAccount, Settings.MyPassword);
        service.Url = new Uri(Settings.ExchangeServer);

var appointment = new Microsoft.Exchange.WebServices.Data.Appointment(service);
appointment.Subject = setAppointmentDto.Title;
appointment.Body = setAppointmentDto.Message;
appointment.Location = setAppointmentDto.Location;

 ...

appointment.Save(SendInvitationsMode.SendToAllAndSaveCopy);

This adds an appointment for the user specified in the credentials.

I do not have the password for the currently logged in user. Since I am using Windows Authentication (Active Directory Account), is there a way to somehow use this authentication information to use the Exchange Web service with the account of the user who uses the web application? Because of security it is not possible to retrieve the user's password from Active Directory.

Is there another way of doing this? Is it possible to create an appointment for another user as the user who uses the service?

Greetings

Alexander

Upvotes: 0

Views: 1524

Answers (1)

Stephen
Stephen

Reputation: 803

You have two options for setting the Credentials.

// Connect by using the default credentials of the authenticated user.
service.UseDefaultCredentials = true;

or

// Connect by using the credentials of user1 at contoso.com.
service.Credentials = new WebCredentials("[email protected]", "password");

Source for the above and full info is here http://msdn.microsoft.com/EN-US/library/office/ff597939(v=exchg.80).aspx

Microsoft also recommends using Autodiscover to set the URL endpoint

// Use Autodiscover to set the URL endpoint.
service.AutodiscoverUrl("[email protected]");

If you wanted to create an appointment for another user you would use

appointment.RequiredAttendees.Add("[email protected]");

or

appointment.OptionalAttendees.Add("[email protected]");

Depending if they were required or optional.

However, this changes the appointment to a meeting. The meeting request is just an appointment with attendees.

Upvotes: 1

Related Questions