首页 文章

从ASP.NET MVC Intranet应用程序向Exchange日历添加约会

提问于
浏览
0

我有一个ASP.NET MVC 4 Intranet应用程序 .

该应用程序使用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应用程序的用户的帐户一起使用?由于安全性,无法从Active Directory检索用户的密码 .

还有另一种方法吗?是否可以为使用该服务的用户创建另一个用户的约会?

问候

亚历山大

1 回答

  • 0

    您有两种设置凭据的选项 .

    // 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 endpoints

    // Use Autodiscover to set the URL endpoint.
    service.AutodiscoverUrl("user1@contoso.com");
    

    如果您想为您将使用的其他用户创建约会

    appointment.RequiredAttendees.Add("user2@contoso.com");
    

    要么

    appointment.OptionalAttendees.Add("user3@contoso.com");
    

    取决于它们是否是必需的或可选的 .

    但是,这会将约会更改为 Session . Session 请求只是与与会者的约会 .

相关问题