惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

酷 壳 – CoolShell
酷 壳 – CoolShell
H
Hacker News: Front Page
P
Palo Alto Networks Blog
T
ThreatConnect
Apple Machine Learning Research
Apple Machine Learning Research
博客园_首页
T
True Tiger Recordings
P
Privacy & Cybersecurity Law Blog
B
Blog
IT之家
IT之家
Last Week in AI
Last Week in AI
F
Full Disclosure
Hacker News: Ask HN
Hacker News: Ask HN
C
Comments on: Blog
Microsoft Azure Blog
Microsoft Azure Blog
C
Cybersecurity and Infrastructure Security Agency CISA
Microsoft Security Blog
Microsoft Security Blog
博客园 - 【当耐特】
N
News and Events Feed by Topic
NISL@THU
NISL@THU
腾讯CDC
雷峰网
雷峰网
Security Latest
Security Latest
李成银的技术随笔
M
Microsoft Research Blog - Microsoft Research
L
LangChain Blog
L
Lohrmann on Cybersecurity
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
C
Check Point Blog
Y
Y Combinator Blog
Recent Announcements
Recent Announcements
博客园 - Franky
N
News | PayPal Newsroom
V
V2EX
A
About on SuperTechFans
The Register - Security
The Register - Security
月光博客
月光博客
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
Google Online Security Blog
Google Online Security Blog
MyScale Blog
MyScale Blog
Cisco Talos Blog
Cisco Talos Blog
Vercel News
Vercel News
WordPress大学
WordPress大学
C
Cyber Attacks, Cyber Crime and Cyber Security
The Hacker News
The Hacker News
IntelliJ IDEA : IntelliJ IDEA – the Leading IDE for Professional Development in Java and Kotlin | The JetBrains Blog
IntelliJ IDEA : IntelliJ IDEA – the Leading IDE for Professional Development in Java and Kotlin | The JetBrains Blog
爱范儿
爱范儿
A
Arctic Wolf
L
LINUX DO - 最新话题
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More

博客园 - 害羞的狮子王

无责任Windows Azure SDK .NET开发入门篇三[使用Azure AD 管理用户信息--3.5 Delete删除用户] 无责任Windows Azure SDK .NET开发入门篇三[使用Azure AD 管理用户信息--3.4 Edit修改用户信息] 无责任Windows Azure SDK .NET开发入门篇三[使用Azure AD 管理用户信息--3.3 Details用户详细信息] - 害羞的狮子王 无责任Windows Azure SDK .NET开发入门篇三[使用Azure AD 管理用户信息--3.1 Index用户列表] 无责任Windows Azure SDK .NET开发入门篇三[使用Azure AD 管理用户信息] - 害羞的狮子王 无责任Windows Azure SDK .NET开发入门篇二[使用Azure AD 进行身份验证-2.2身份验证开发] - 害羞的狮子王 无责任Windows Azure SDK .NET开发入门篇二[使用Azure AD 进行身份验证--2.1使用Azure AD需要了解几个概念] 无责任Windows Azure SDK .NET开发入门篇二[使用Azure AD 进行身份验证] 无责任Windows Azure SDK .NET开发入门篇一[Windows Azure开发前准备工作] 建立小型开发团队的工作协作:翻译工作 - 害羞的狮子王 建立小型开发团队的工作协作:讨论区 建立小型开发团队的工作协作:BugList 建立小型开发团队的工作协作:任务日历 建立小型开发团队的工作协作:简单的文档管理 建立小型开发团队的工作协作:管理调查和投票 - 害羞的狮子王 建立小型开发团队的工作协作:管理链接 建立小型开发团队的工作协作:总览效果图 感谢微软BPOS4China技术支持组 远程为服务器安装Windows 2008 Server - 害羞的狮子王
无责任Windows Azure SDK .NET开发入门篇三[使用Azure AD 管理用户信息--3.2 Create创建用户]
害羞的狮子王 · 2015-08-10 · via 博客园 - 害羞的狮子王

3.2 Create创建用户

[HttpPost, Authorize]
public async Task<ActionResult> Create(
    [Bind(Include = "UserPrincipalName,AccountEnabled,PasswordProfile,MailNickname,DisplayName,GivenName,Surname,JobTitle,Department")]
    User user)
{
    ActiveDirectoryClient client = null;
    try
    {
        client = AuthenticationHelper.GetActiveDirectoryClient();
        await client.Users.AddUserAsync(user);
    }
    catch (Exception e)
    {
        if (e.Message == "Authorization Required.")
        {
            HttpContext.GetOwinContext().Authentication.Challenge(OpenIdConnectAuthenticationDefaults.AuthenticationType);
        }
        return View();
    }
    return RedirectToAction("Index");
}

Create的代码同样很清晰,采用了Bind Include简化了View的表单提交。对应的View的代码如下

@model Microsoft.Azure.ActiveDirectory.GraphClient.User

@{
    ViewBag.Title = "CreateUser";
}

<h2>Create User</h2>

@using (Html.BeginForm("Create", "AzureActiveDirectory", null, FormMethod.Post, new { @class = "form-horizontal" }))
{
    @Html.ValidationSummary(true)


        <div class="form-group">
            @Html.LabelFor(model => model.UserPrincipalName, "用户名(英文名@域名)", new { @class = "col-sm-2 control-label" })
            <div class="col-sm-10">
                @Html.TextBoxFor(model => model.UserPrincipalName)
                @Html.ValidationMessageFor(model => model.UserPrincipalName)
            </div>
        </div>

        <div class="form-group">
            @Html.LabelFor(model => model.AccountEnabled, "账号启用", new { @class = "col-sm-2 control-label" })
            <div class="col-sm-10">
                @Html.EditorFor(model => model.AccountEnabled)
                @Html.ValidationMessageFor(model => model.AccountEnabled)
            </div>
        </div>

        <div class="form-group">
            @Html.LabelFor(model => model.PasswordProfile.Password, "密码(必须强密码)", new { @class = "col-sm-2 control-label" })
            <div class="col-sm-10">
                @Html.TextBoxFor(model => model.PasswordProfile.Password)
                @Html.ValidationMessageFor(model => model.PasswordProfile.Password)
            </div>
        </div>

        <div class="form-group">
            @Html.LabelFor(model => model.MailNickname, "别名(必须英文名)", new { @class = "col-sm-2 control-label" })
            <div class="col-sm-10">
                @Html.TextBoxFor(model => model.MailNickname)
                @Html.ValidationMessageFor(model => model.MailNickname)
            </div>
        </div>

        <div class="form-group">
            @Html.LabelFor(model => model.DisplayName, "显示名称", new { @class = "col-sm-2 control-label" })
            <div class="col-sm-10">
                @Html.TextBoxFor(model => model.DisplayName)
                @Html.ValidationMessageFor(model => model.DisplayName)
            </div>
        </div>

        <div class="form-group">
            @Html.LabelFor(model => model.GivenName, "名字", new { @class = "col-sm-2 control-label" })
            <div class="col-sm-10">
                @Html.TextBoxFor(model => model.GivenName)
                @Html.ValidationMessageFor(model => model.GivenName)
            </div>
        </div>

        <div class="form-group">
            @Html.LabelFor(model => model.Surname, "姓氏", new { @class = "col-sm-2 control-label" })
            <div class="col-sm-10">
                @Html.TextBoxFor(model => model.Surname)
                @Html.ValidationMessageFor(model => model.Surname)
            </div>
        </div>

        <div class="form-group">
            @Html.LabelFor(model => model.JobTitle, "职务", new { @class = "col-sm-2 control-label" })
            <div class="col-sm-10">
                @Html.TextBoxFor(model => model.JobTitle)
                @Html.ValidationMessageFor(model => model.JobTitle)
            </div>
        </div>

        <div class="form-group">
            @Html.LabelFor(model => model.Department, "部门", new { @class = "col-sm-2 control-label" })
            <div class="col-sm-10">
                @Html.TextBoxFor(model => model.Department)
                @Html.ValidationMessageFor(model => model.Department)
            </div>
        </div>
        <p>
            <input type="submit" value="Create" class="btn btn-primary" />
        </p>
}

执行后的结果为

1

创建成功跳转到Index页面

3

为了让大家清楚的理解User属性对应的Azure门户管理上的提示,我在View中比较详细的做了说明,下表可以更清晰的看到对应

属性名

门户对应

要求

UserPrincipalName

用户名

英文名@域名

AccountEnabled

账号状态

 

Password

密码

必须强密码

MailNickname

别名

必须英文名

DisplayName

显示名称

 

GivenName

名字

 

Surname

姓氏

 

JobTitle

职务

 

Department

部门

 

StreetAddress

街道地址

 

City

城市

 

State

省/自治区/直辖市

 

Country

国家或地区

 

PhysicalDeliveryOfficeName

办公室号码

 

TelephoneNumber

办公电话

 

PostalCode

邮政编码