问题描述
我创建扩展名:
SchemaExtension objExtDef =新的SchemaExtension()
{
说明=存储用户日期的扩展名",
ID ="UserDates",
属性=新的List< ExtensionSchemaProperty>()
{
new ExtensionSchemaProperty(){Name ="CreateDate",Type ="DateTime" },
new ExtensionSchemaProperty(){Name ="PasswordChangeDate",Type ="DateTime" }
},
TargetTypes = new List< string>()
{
用户"
}
};
SchemaExtension schemaExtension = Task.Run(()=> graphserviceClient.SchemaExtensions.Request().AddAsync(objExtDef)).Result;
SchemaExtension objExtDef = new SchemaExtension()
{
Description = "Extention to Store User Dates",
Id = "UserDates",
Properties = new List<ExtensionSchemaProperty>()
{
new ExtensionSchemaProperty() { Name = "CreateDate", Type = "DateTime" },
new ExtensionSchemaProperty() { Name = "PasswordChangeDate", Type = "DateTime" }
},
TargetTypes = new List<string>()
{
"User"
}
};
SchemaExtension schemaExtension = Task.Run(() => graphserviceClient.SchemaExtensions.Request().AddAsync(objExtDef)).Result;
使其可用:
var schemaExtension =新的SchemaExtension
{
状态=可用",
};
var result = Task.Run(()=> graphserviceClient.SchemaExtensions ["extuce7u7qp_UserDates"].Request().UpdateAsync(schemaExtension)).Result;
var schemaExtension = new SchemaExtension
{
Status = "Available",
};
var result = Task.Run(() => graphserviceClient.SchemaExtensions["extuce7u7qp_UserDates"].Request().UpdateAsync(schemaExtension)).Result;
搜索并确认它已创建并可用:
Searched and confirmed that it is created and available :
var lstAllExtensions = Task.Run(()=> graphserviceClient.SchemaExtensions.Request().Filter("id%20eq%20'extuce7u7qp_UserDates'").GetAsync()).Result;
var lstAllExtensions = Task.Run(() => graphserviceClient.SchemaExtensions.Request().Filter("id%20eq%20'extuce7u7qp_UserDates'").GetAsync()).Result;
尝试在该扩展名中添加用户以及其他数据:
Trying to add user along with additional data in that extension :
Microsoft.Graph.User objNewUser =新的Microsoft.Graph.User
{
AccountEnabled = true,
DisplayName = string.Format("{0} {1}",objUser.FirstName,objUser.LastName),
MailNickname ="TestUC",
PasswordProfile =新的PasswordProfile
{
密码="testpass",
ForceChangePasswordNextSignIn = false
},
UserPrincipalName = string.Format("{0}@test.onmicrosoft.com",objUser.UserIdentity),
GivenName = objUser.FirstName,
姓= objUser.LastName,
City = objUser.Address!= null吗? objUser.Address.City:null,
国家= objUser.Address!=空吗? objUser.Address.Country:null,
状态= objUser.Address!=空吗? objUser.Address.Region:空,
MobilePhone =!string.IsNullOrEmpty(objUser.Phone)吗? objUser.Phone:null,
PreferredLanguage = objUser.PreferredLanguage,
AdditionalData = dctExtensions
};
Microsoft.Graph.User objNewUser = new Microsoft.Graph.User
{
AccountEnabled = true,
DisplayName = string.Format("{0} {1}", objUser.FirstName, objUser.LastName),
MailNickname = "TestUC",
PasswordProfile = new PasswordProfile
{
Password = "testpass",
ForceChangePasswordNextSignIn = false
},
UserPrincipalName = string.Format("{0}@test.onmicrosoft.com", objUser.UserIdentity),
GivenName = objUser.FirstName,
Surname = objUser.LastName,
City = objUser.Address != null ? objUser.Address.City : null,
Country = objUser.Address != null ? objUser.Address.Country : null,
State = objUser.Address != null ? objUser.Address.Region : null,
MobilePhone = !string.IsNullOrEmpty(objUser.Phone) ? objUser.Phone : null,
PreferredLanguage = objUser.PreferredLanguage,
AdditionalData = dctExtensions
};
Microsoft.Graph.User objCreatedUser = Task.Run(()=> graphserviceClient.Users.Request().AddAsync(
objNewUser
)).Result;
Microsoft.Graph.User objCreatedUser = Task.Run(() => graphserviceClient.Users.Request().AddAsync(
objNewUser
)).Result;
这引发了扩展ID无效的异常.
That is throwing exception that the extension ID is not valid.
这是较早的工作.
推荐答案
通过在此处提供的代码中进行少量修改,我就能成功创建用户.
I am able to create the user successfully with few modifications in the code which you have provided here.
为什么要在分配状态时创建新的SchemaExtension对象?
Why are you creating a new SchemaExtension object while assigning the status ?
var schemaExtension =新的SchemaExtension
{
状态=可用",
};
var schemaExtension = new SchemaExtension
{
Status = "Available",
};
我已经从扩展列表中检索了SchemaExtension对象,并将Status属性设置为"Available".如下:-
I have retrieved the SchemaExtension object from extensions list and set the Status property to "Available" as below :-
SchemaExtension testSchema = new SchemaExtension();testSchema = lstAllExtensions.First<SchemaExtension>();testSchema.Status = "Available";
此外,我还为dctExtensions添加了代码,如下所示-
Also, I have added code for dctExtensions like below -
IDictionary<string, object> dctExtensions = new Dictionary<string, object>();dctExtensions.Add("ext8sj4y2pf_UserDates", objUserDatesExtension);
这篇关于Azure AD模式扩展的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!