我想從sitecore 8.1中的代碼創建自定義域的用戶。我成功地可以使用下面的代碼來創建用戶:如何將自定義配置文件分配給sitecore中的自定義域用戶
[HttpPost]
public string RegisterUser(SurveyMonkeyUser userInfo)
{
string userId = "0";
string Domain = "website"; //to be taken from config
string ProfileItemId = "{7D473841-D585-43F6-9DF4-400313D945EC}"; //to be taken from config
if (!AccountExists(Domain + userInfo.Username))
{
string domainUser = string.Concat(Domain ,@"\", userInfo.Username.Replace(" ",""));
var user = Sitecore.Security.Accounts.User.Create(domainUser , "pass123");
user.Profile.ProfileItemId = ProfileItemId;
user.Profile.SetCustomProperty("FirstName", userInfo.FirstName);
user.Profile.SetCustomProperty("LastName", userInfo.LastName);
user.Profile.SetCustomProperty("Email", userInfo.Email);
user.Profile.SetCustomProperty("DateOfBirth", userInfo.DateOfBirth);
user.Profile.SetCustomProperty("Gender", userInfo.Gender);
user.Profile.SetCustomProperty("Location", userInfo.Location);
user.Profile.SetCustomProperty("Occupation", userInfo.Occupation);
user.Profile.SetCustomProperty("SectorEmployment", userInfo.SectorEmployment);
user.Profile.SetCustomProperty("Salary", userInfo.Salary);
user.Profile.SetCustomProperty("MaritalStatus", userInfo.MaritalStatus);
user.Profile.SetCustomProperty("MobileNumber", userInfo.MobileNumber);
user.Profile.Save();
user.Profile.Reload();
var username = user.Name;
userId = "Account Created Successfully " + user.Name;
}
else
{
userId = "user already exist";
}
return userId;
}
但它的自定義屬性是不可見在Sitecore的後端,但是調試過程中,我可以看到prevuiously創建使用Sitecore.Security.Accounts.User.FromName(@"website\SyedAhsanJaffri",true).Profile.SerializedData
我得到的所有屬性
Count = 13
[0]: {[digestcredentialhash, a287effab21c2ec84696e4eef4ca2171]}
[1]: {[digestcredentialhashwithoutdomain, 767c0012faf8e872581d3ac5919db895]}
[2]: {[FirstName, Syed Ahsan]}
[3]: {[LastName, Jaffri]}
[4]: {[Email, [email protected]]}
[5]: {[DateOfBirth, 14/08/1985]}
[6]: {[Gender, Male]}
[7]: {[Location, Karachi]}
[8]: {[Occupation, Software Engineer]}
[9]: {[SectorEmployment, IT]}
[10]: {[Salary, 351212]}
[11]: {[MaritalStatus, Single]}
[12]: {[MobileNumber, 923312190031]}
所有用戶的個人資料
在後端我必須手動更改自定義配置文件:)才能查看我的屬性。
你這個創建自定義配置文件用戶? –