sye*_*fri 2 asp.net-membership sitecore sitecore8
我试图从sitecore 8.1中的代码创建自定义域的用户.我成功地使用以下代码创建用户:
[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;
}
Run Code Online (Sandbox Code Playgroud)
但它的自定义属性在sitecore的后端不可见,但在调试期间,我可以看到使用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, username@xxxxx.com]}
[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]}
Run Code Online (Sandbox Code Playgroud)
在后端我必须手动更改自定义配置文件:)以查看我的属性.
您可以打开App_Config\Securiry\Domains.config并在那里配置默认配置文件项ID,例如:
<domain name="CommerceUsers" defaultProfileItemId="{0FFEC1BD-4D35-49CF-8B7D-7F01930834ED}" ensureAnonymousUser="false" />
Run Code Online (Sandbox Code Playgroud)
PS但是你的代码看起来是正确的.我想知道你的不行.确保您传输正确的ID.仔细检查您是否从Core数据库传输了配置文件项的ID(而不是配置文件模板的ID).
| 归档时间: |
|
| 查看次数: |
422 次 |
| 最近记录: |