无责任Windows Azure SDK .NET开发入门篇三[使用Azure AD 管理用户信息--3.2 Create创建用户]
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>
}
执行后的结果为

创建成功跳转到Index页面

为了让大家清楚的理解User属性对应的Azure门户管理上的提示,我在View中比较详细的做了说明,下表可以更清晰的看到对应
|
属性名 |
门户对应 |
要求 |
|
UserPrincipalName |
用户名 |
英文名@域名 |
|
AccountEnabled |
账号状态 |
|
|
Password |
密码 |
必须强密码 |
|
MailNickname |
别名 |
必须英文名 |
|
DisplayName |
显示名称 |
|
|
GivenName |
名字 |
|
|
Surname |
姓氏 |
|
|
JobTitle |
职务 |
|
|
Department |
部门 |
|
|
StreetAddress |
街道地址 |
|
|
City |
城市 |
|
|
State |
省/自治区/直辖市 |
|
|
Country |
国家或地区 |
|
|
PhysicalDeliveryOfficeName |
办公室号码 |
|
|
TelephoneNumber |
办公电话 |
|
|
PostalCode |
邮政编码 |
无责任Windows Azure SDK .NET开发入门篇三[使用Azure AD 管理用户信息--3.2 Create创建用户]的更多相关文章
- 无责任Windows Azure SDK .NET开发入门篇三[使用Azure AD 管理用户信息]
三.使用Azure AD管理用户信息 在上一章我们采用OpenID的方案和Azure AD交互进行身份验证,本章节我们继续了解如何在Azure AD中创建用户,列出用户信息,修改用户信息和删除用户信息 ...
- 无责任Windows Azure SDK .NET开发入门篇三[使用Azure AD 管理用户信息--3.4 Edit修改用户信息]
3.4 Edit修改用户信息 我们用FormCollection简化了表单提交,非常方便的进行用户信息修改. [HttpPost, Authorize] public async Task<Ac ...
- 无责任Windows Azure SDK .NET开发入门篇三[使用Azure AD 管理用户信息--3.3 Details用户详细信息]
3.3 Details用户详细信息 用户详细信息是通过objectId获取.代码如下 public async Task<ActionResult> Details(string obje ...
- 无责任Windows Azure SDK .NET开发入门篇三[使用Azure AD 管理用户信息--3.1 Index用户列表]
3.1 Index用户列表 或许当前域下的用户列表 [Authorize] public async Task<ActionResult> Index() { var userList = ...
- 无责任Windows Azure SDK .NET开发入门篇三[使用Azure AD 管理用户信息--3.5 Delete删除用户]
3.5 Delete删除用户 删除也是通过ObjectID获得对象进行删除 [Authorize] public async Task<ActionResult> Delete(strin ...
- 无责任Windows Azure SDK .NET开发入门篇二[使用Azure AD 进行身份验证-2.2身份验证开发]
2.2身份验证开发 在我们的案例中,我们是用户通过Web应用程序进行身份识别. 上面的图示说明了如下的一些概念 l Azure AD 是标识提供程序,负责对组织的目录中存在的用户和应用程序的标识进行验 ...
- 无责任Windows Azure SDK .NET开发入门篇二[使用Azure AD 进行身份验证]
二.使用Azure AD进行身份验证 之所以将Azure AD 作为开始,是应为基本上我们所有应用都需要进行安全管理.Azure Active Directory (Azure AD) 通过以下方式简 ...
- 无责任Windows Azure SDK .NET开发入门篇二[使用Azure AD 进行身份验证--2.1使用Azure AD需要了解几个概念]
2.1使用Azure AD需要了解几个概念 l Azure AD目录 当你注册 Microsoft 云服务时,便会获得一个 Azure AD 目录.你可根据需要创建更多的目录.例如,可以将第一个目录保 ...
- 无责任Windows Azure SDK .NET开发入门篇(一):开发前准备工作
Windows Azure开发前准备工作 什么是 Azure SDK for .NET?微软官方告诉我们:Azure SDK for .NET 是一套应用程序,其中包括 Visual Studio 工 ...
随机推荐
- 【英语】Bingo口语笔记(67) - turn系列
- jboss集成eclipse
eclipse Kepler + Jboss7.1 参考引用文档: http://www.tekdigest.com/how-to-install-jboss-tools-in-eclipse.htm ...
- Android WebView中那些不得不解决的坑~~
前面那张hybrid开发心得 有人问 怎么解决不用onJsPrompt 来回调js函数的问题.其实很简单,就是在在你的jscalljava回调函数内 另外开个线程去load js代码即可: wb.po ...
- JS判断手机访问页面,根据手机访问或者PC访问跳转
当用户访问你网站时,如果是PC端访问,则不作处理,如果是手机或者平板访问,就跳转到自己定义的手机页面去,这个在做webapp的时候经常用到,把代码分享给大家,希望对大家有所帮助. 首先,你要在页面中引 ...
- [再寄小读者之数学篇](2014-11-19 $\sin(x+y)=\sin x\cos y+\cos x\sin y$)
$$\bex \sin(x+y)=\sin x\cos y+\cos x\sin y. \eex$$ Ref. [Proof Without Words: Sine Sum Identity, The ...
- 使用c++11改写loki的TypeList
最近看了C++11的一些特性,最感兴趣的是可变模板参数,自动类型推断和匿名函数. Loki中的TypeList,是需要递归定义的,并且需要一个NullType作为尾节点. 可变模板参数使得实现Type ...
- C#语言基础02
字符串:string s="ab";string s1="a\nb";//n:newline或者next的意思. string s="a\\b&quo ...
- Windows Live Writer安装与使用
无耻的转贴一份WLW的安转与使用指南 =========================转贴分隔线=========================== [Windows Live Writer安 ...
- FlatBuffers与protobuf性能比较
FlatBuffers发布时,顺便也公布了它的性能数据,具体数据请见Benchmark. 它的测试用例由以下数据构成"a set of about 10 objects containing ...
- DOCTYPE的笔记
平时用HTML5 所以都直接简写doctype <!DOCTYPE html> <html> 从来没考虑这个东西全文是什么 <!DOCTYPE html PUBLIC & ...