無責任Windows Azure SDK .NET開發入門篇三[使用Azure AD 管理用戶信息--3.5 Delete刪除用戶]

3.5 Delete刪除用戶

刪除也是經過ObjectID得到對象進行刪除async

[Authorize]
public async Task<ActionResult> Delete(string objectId)
{
    try
    {
        ActiveDirectoryClient client = AuthenticationHelper.GetActiveDirectoryClient();
        var user = (User)await client.Users.GetByObjectId(objectId).ExecuteAsync();
        await user.DeleteAsync();
        return RedirectToAction("Index");
    }
    catch (Exception exception)
    {
        ModelState.AddModelError("", exception.Message);
        return RedirectToAction("Index");
    }
}
相關文章
相關標籤/搜索