如何使用 sitecore 规则中的规则和操作

How to work with rules and actions in sitecore rules

我正在尝试使用 Sitecore 规则将用户添加到特定角色。我正在考虑在 /Actions/New User Action 项目的 Items Saved 事件中编写代码,但我不确定要写什么。甚至可以通过规则将用户添加到角色吗?如果是这样,我如何使用类型、代码、参考和语言字段来做到这一点?

使用以下代码创建程序集,然后在 app_include 中的 ["event name="item:saved"] 处理程序中调用程序集,或者在类型字段中设置 "Namespace.AddNewUser.AddUser, yourAssembly"。

public void AddUser(string domain, string firstName, string lastName, string email, 
        string comment, string telephoneNumber, string jobTitle)
{
    string userName = string.Concat(firstName, lastName);
    userName = string.Format(@"{0}\{1}", domain, userName);

    // You can manually set the password or from Sitecore's generator
    string newPassword = Membership.GeneratePassword(10, 3);

    try
    {
        if (!User.Exists(userName))
        {
            Membership.CreateUser(userName, newPassword, email);

            // Edit the profile information
            Sitecore.Security.Accounts.User user = Sitecore.Security.Accounts.User.FromName(userName, true);
            Sitecore.Security.UserProfile userProfile = user.Profile;
            userProfile.FullName = string.Format("{0} {1}", firstName, lastName);
            userProfile.Comment = comment;

            // Assigning the user profile template
            userProfile.SetPropertyValue("ProfileItemId", "{this is profileItem's GUID}");

            // Have modified the user template to also contain telephone number and job title.
            userProfile.SetCustomProperty("TelephoneNumber", telephoneNumber);
            userProfile.SetCustomProperty("JobTitle", jobTitle);
            userProfile.Save();
        }
    }
    catch (Exception ex)
    {
        Sitecore.Diagnostics.Log.Error(string.Format("Error in Client.Project.Security.UserMaintenance (AddUser): Message: {0}; Source:{1}", ex.Message, ex.Source), this);
    }
}