【问题标题】:Call Profile Provider By Name in Profile config在配置文件配置中按名称调用配置文件提供程序
【发布时间】:2012-02-27 07:46:31
【问题描述】:

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

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

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

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

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

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

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

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

【问题讨论】:

  • 有关如何将更多安全提供商插入 Sitecore 的更多详细信息,请参阅此内容:sdn.sitecore.net/Articles/Security/…
  • @YanSklyarenko 感谢您的链接。有没有我可以参考的示例代码。谢谢
  • 有一个名为 YAFIntegration(Yet Another Forum 集成)的共享源项目。它实现了整个提供程序集,您可以将其用作示例(尽管不是一个简单的示例)。这是链接:trac.sitecore.net/YAFIntegration

标签: sitecore sitecore6 provider profile-provider


【解决方案1】:

这是我最近使用电子邮件营销管理器为客户设置一些自定义配置文件的一些代码。如果此代码使用特定于 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));

            }
        }
    }

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2010-09-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-03-05
    相关资源
    最近更新 更多