无责任Windows Azure SDK .NET开发入门篇三[使用Azure AD 管理用户信息--3.5 Delete删除用户]

时间:2021-07-14 15:07:10

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");
}
}