用戶詳細信息是經過objectId獲取。代碼以下async
public async Task<ActionResult> Details(string objectId) { try { ActiveDirectoryClient client = AuthenticationHelper.GetActiveDirectoryClient(); var user = (User)await client.Users.GetByObjectId(objectId).ExecuteAsync(); return View(user); } catch (Exception e) { if (e.Message == "Authorization Required.") { HttpContext.GetOwinContext().Authentication.Challenge(OpenIdConnectAuthenticationDefaults.AuthenticationType); } return View(); } }
對應的View代碼以下ui
@model Microsoft.Azure.ActiveDirectory.GraphClient.User @{ ViewBag.Title = "UserDetails"; } <h2>User Details</h2> <div class="form-horizontal"> <div class="form-group"> @Html.LabelFor(model => model.UserPrincipalName, "用戶名(全名)", new { @class = "col-sm-2 control-label" }) <div class="col-sm-10"> @Html.DisplayFor(model => model.UserPrincipalName) </div> </div> <div class="form-group"> @Html.LabelFor(model => model.MailNickname, "別名", new { @class = "col-sm-2 control-label" }) <div class="col-sm-10"> @Html.DisplayFor(model => model.MailNickname) </div> </div> <div class="form-group"> @Html.LabelFor(model => model.City, "城市", new { @class = "col-sm-2 control-label" }) <div class="col-sm-10"> @Html.DisplayFor(model => model.City) </div> </div> <div class="form-group"> @Html.LabelFor(model => model.Country, "國家或地區", new { @class = "col-sm-2 control-label" }) <div class="col-sm-10"> @Html.DisplayFor(model => model.Country) </div> </div> <div class="form-group"> @Html.LabelFor(model => model.Department, "部門", new { @class = "col-sm-2 control-label" }) <div class="col-sm-10"> @Html.DisplayFor(model => model.Department) </div> </div> <div class="form-group"> @Html.LabelFor(model => model.DisplayName, "顯示名稱", new { @class = "col-sm-2 control-label" }) <div class="col-sm-10"> @Html.DisplayFor(model => model.DisplayName) </div> </div> <div class="form-group"> @Html.LabelFor(model => model.PhysicalDeliveryOfficeName, "辦公室號碼", new { @class = "col-sm-2 control-label" }) <div class="col-sm-10"> @Html.DisplayFor(model => model.PhysicalDeliveryOfficeName) </div> </div> <div class="form-group"> @Html.LabelFor(model => model.TelephoneNumber, "辦公電話", new { @class = "col-sm-2 control-label" }) <div class="col-sm-10"> @Html.DisplayFor(model => model.TelephoneNumber) </div> </div> <div class="form-group"> @Html.LabelFor(model => model.GivenName, "名字", new { @class = "col-sm-2 control-label" }) <div class="col-sm-10"> @Html.DisplayFor(model => model.GivenName) </div> </div> <div class="form-group"> @Html.LabelFor(model => model.JobTitle, "職務", new { @class = "col-sm-2 control-label" }) <div class="col-sm-10"> @Html.DisplayFor(model => model.JobTitle) </div> </div> <div class="form-group"> @Html.LabelFor(model => model.PostalCode, "郵政編碼", new { @class = "col-sm-2 control-label" }) <div class="col-sm-10"> @Html.DisplayFor(model => model.PostalCode) </div> </div> <div class="form-group"> @Html.LabelFor(model => model.State, "省/自治區/直轄市", new { @class = "col-sm-2 control-label" }) <div class="col-sm-10"> @Html.DisplayFor(model => model.State) </div> </div> <div class="form-group"> @Html.LabelFor(model => model.StreetAddress, "街道地址", new { @class = "col-sm-2 control-label" }) <div class="col-sm-10"> @Html.DisplayFor(model => model.StreetAddress) </div> </div> <div class="form-group"> @Html.LabelFor(model => model.Surname, "姓氏", new { @class = "col-sm-2 control-label" }) <div class="col-sm-10"> @Html.DisplayFor(model => model.Surname) </div> </div> <div class="form-group"> @Html.LabelFor(model => model.UserType, new { @class = "col-sm-2 control-label" }) <div class="col-sm-10"> @Html.DisplayFor(model => model.UserType) </div> </div> </div> <table> <tbody> <tr> <td> @Html.ActionLink("Edit", "Edit", new { objectId = Model.ObjectId }, new { @class = "btn btn-primary" }) </td> <td> @Html.ActionLink("Delete", "Delete", new { objectId = Model.ObjectId }, new { @class = "btn btn-warning" }) </td> <td> @Html.ActionLink("List", "Index", null, new { @class = "btn btn-info" }) </td> </tr> </tbody> </table>