0

我有一个旧系统(sitecore 6.1),它已经有一个配置文件提供程序作为管理部分的默认配置文件。

现在,我需要为普通用户添加另一个自定义的 SQL 配置文件提供程序(在不同的表中)。

但我的问题是剂量系统如何知道在代码中使用哪个配置文件提供程序?

有什么我可以做的类似于:

System.Web.Security.Membership.Providers[providerString];

这样我就可以在我的代码中相应地调用自定义配置文件提供程序。

或者在这种情况下最好的做法是什么。

我已经浪费了 1 个小时来尝试浏览 sitecore 文档,但那里没有太多可用的文档。

4

1 回答 1

0

这是我最近使用电子邮件营销管理器为客户设置一些自定义配置文件的一些代码。如果此代码使用特定于 ECM 的某些类,它会创建一个新用户,初始化一个配置文件类,然后将该配置文件分配给新用户。然后它为刚刚创建的用户设置一些自定义属性。它向您展示了如何根据用户调用配置文件以及分配用于该用户的配置文件。这可能会帮助或帮助其他人。

   public static void Process(List<Subscriber> userItems, Item targetAudienceDefinitionItem)
    {
        foreach (Subscriber user in userItems)
        {
            // you can also just pass it the id of the target audience as a string
            Sitecore.Modules.EmailCampaign.TargetAudienceBase target = Sitecore.Modules.EmailCampaign.TargetAudience.FromItem(targetAudienceDefinitionItem);

            string campaignname = target.ManagerRoot.Settings.CommonDomain;
            string realUsername = campaignname + "\\" + user.UserName;

            using (new SecurityDisabler())
            {
                User newUser;
                if (!Sitecore.Security.Accounts.User.Exists(realUsername))
                {
                    // create a new user and assign it to the email domain specified in the manager root item
                    newUser = Sitecore.Security.Accounts.User.Create(campaignname + "\\" + user.UserName, System.Web.Security.Membership.GeneratePassword(8,1));
                }
                else
                    // get back the existing user
                    newUser = User.FromName(realUsername, false);

                // get back the current user profile  
                UserProfile subscriber = newUser.Profile;

                // reset the profile to be the profile specified in the manager root
                subscriber.ProfileItemId = target.ManagerRoot.Settings.SubscriberProfile;
                subscriber.Save();

                // built in properties are set like this
                subscriber.Email = user.Email;

                // set custom property value 
                subscriber["Address"] = user.Address;


                // or long method 
                subscriber.SetCustomProperty("Address", user.Address);

                subscriber.Save();
                // now subscribe the user to the target audience subscriber list
                target.Subscribe(Contact.FromName(newUser.Name));

            }
        }
    }
于 2012-03-13T18:49:04.030 回答