【发布时间】:2017-05-24 12:04:11
【问题描述】:
我想在我的 Enterprise Exchange 帐户中创建一个新日历,但我总是获得相同的“拒绝访问”异常 mscorlib.ni.dll 中出现“System.UnauthorizedAccessException”类型的异常,但未在用户代码中处理 附加信息:访问被拒绝。 (来自 HRESULT 的异常:0x80070005 (E_ACCESSDENIED))
这是我的代码,为这个问题做了很多简化:
private const string ExchangeActiveSync = "{6833942B-ABDA-4C20-9757-4F9252396BD4}";
UserDataAccountStore userDataAccountStore = await UserDataAccountManager.RequestStoreAsync(UserDataAccountStoreAccessType.AllAccountsReadOnly);
//Read-only access to app user data accounts and system user data accounts.
//AllAccountsReadOnly = 0,
//Read/write access to the current app's user data accounts.
//AppAccountsReadWrite = 1
//So AllAccountsReadWrite is missing :(
IReadOnlyList<UserDataAccount> listUserAccounts = await userDataAccountStore.FindAccountsAsync();
string accountId= (from account in listUserAccounts where account.DeviceAccountTypeId.Equals(ExchangeActiveSync) select account.Id).FirstOrDefault();
//accountId = "29,0,af";
string calendarName = Package.Current.DisplayName;
//calendarName = "Test Calendar"
AppointmentStore appointmentStore = await AppointmentManager.RequestStoreAsync(AppointmentStoreAccessType.AllCalendarsReadWrite);
var calendar = await appointmentStore.CreateAppointmentCalendarAsync(calendarName, accountId);
//Here the exception is thrown
calendar.OtherAppReadAccess = AppointmentCalendarOtherAppReadAccess.Full;
calendar.OtherAppWriteAccess = AppointmentCalendarOtherAppWriteAccess.None;
await calendar.SaveAsync();
我还在 package.appxmanifest 中添加了必要的受限功能
<rescap:Capability Name="userDataSystem" />
<rescap:Capability Name="userDataAccountsProvider" />
<rescap:Capability Name="appointmentsSystem" />
我认为主要问题在于 UserDataAccountStoreAccessType 枚举。这里我们错过了“AllAccountsReadWrite”值(就像在日历访问类型中一样)。我认为这是一个巨大的限制。为什么我无法为帐户创建自定义日历?
我注意到这个限制也在系统日历应用程序中,太糟糕了:(
有什么解决办法吗?
非常感谢您的支持。
最好的问候,
弗拉维奥
【问题讨论】:
标签: c# calendar uwp exchange-server