安忍不动如大地,静虑深思如秘藏
雄鹰虽然有时候飞的比鸡还低 但鸡永远也不可能飞到鹰的高度

3.5 Delete删除用户

删除也是通过ObjectID获得对象进行删除

[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");
    }
}
posted on 2015-08-10 19:44  害羞的狮子王  阅读(301)  评论(0编辑  收藏  举报