zoukankan      html  css  js  c++  java
  • 无责任Windows Azure SDK .NET开发入门篇三[使用Azure AD 管理用户信息--3.3 Details用户详细信息]

    3.3 Details用户详细信息

    用户详细信息是通过objectId获取。代码如下

    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代码如下

    @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>
  • 相关阅读:
    .NET微信网页开发之JS-SDK使用步骤和配置信息timestamp(时间戳),nonceStr(随机串),signature(签名),access_token(接口调用凭据)的生成获取讲解
    .NET项目中NLog的配置与使用
    ASP.NET MVC中使用jQuery Ajax通过FormData对象异步提交图片文件到服务端保存并返回保存的图片路径
    Linux CentOS上安装 MySQL 8.0.16
    微信小程序开发之多图片上传+.NET WebAPI后端服务保存图片资源
    MySQL 查询重复数据,删除重复数据保留id最小的一条作为唯一数据
    .NET轻松实现支付宝服务窗网页授权并获取用户相关信息
    .NET微信网页开发之通过UnionID机制,解决用户在不同公众号,或在公众号、移动应用之间帐号统一问题
    Navicat远程连接MySQL 提示1045
    Vs Code推荐安装插件
  • 原文地址:https://www.cnblogs.com/shyleoking/p/4719045.html
Copyright © 2011-2022 走看看