我有一个 ASP.NET 的MVC 4内联网应用程序。
应用程序使用 Windows 身份验证对用户进行身份验证。我可以通过 User.Identity.Name 获得用户名。这包含域名和用户名(MyDomain\Username)。
我现在想通过 Exchange Web 服务 API 向用户日历添加约会。
我可以像下面这样做:
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);
这将为凭据中指定的用户添加约会。
我没有当前登录用户的密码。由于我使用的是Windows身份验证(Active Directory帐户),有没有办法以某种方式使用此身份验证信息将Exchange Web服务与使用该Web应用程序的用户的帐户一起使用?由于安全性的原因,无法从活动目录中检索用户的密码。
有没有其他方法可以做到这一点?是否可以为其他用户创建约会作为使用该服务的用户?
问候
亚历山大
您有两个选项可用于设置凭据。
// Connect by using the default credentials of the authenticated user.
service.UseDefaultCredentials = true;
或
// Connect by using the credentials of user1 at contoso.com.
service.Credentials = new WebCredentials("user1@contoso.com", "password");
以上和完整信息的来源在这里 http://msdn.microsoft.com/EN-US/library/office/ff597939(v=exchg.80).aspx
Microsoft还建议使用自动发现来设置 URL 终结点
// Use Autodiscover to set the URL endpoint.
service.AutodiscoverUrl("user1@contoso.com");
如果要为其他用户创建约会,请使用
appointment.RequiredAttendees.Add("user2@contoso.com");
或
appointment.OptionalAttendees.Add("user3@contoso.com");
取决于它们是必需的还是可选的。
但是,这会将约会更改为会议。会议请求只是与与会者的约会。