gpt4 book ai didi

Sitecore 多个自定义用户配置文件

转载 作者:行者123 更新时间:2023-12-02 19:22:48 25 4
gpt4 key购买 nike

是否可以拥有多个自定义用户配置文件,以及如何设置 Web 配置文件以及如何管理同一 sitecore 实例(相同 VS 解决方案)下的两个网站的自定义配置文件?

我们有一个自定义用户配置文件,新的要求来自于同一 sitecore 实例下的新网站,但第二个网站有新的自定义用户。在开发第二个网站期间,我们创建了第二个自定义用户配置文件,一切都很顺利,我们将 web.config 文件中的 system.web/profile 节点的“继承”属性更改为指向第二个自定义使用配置文件,并且在开发过程中一切正常。

现在的问题是只有一个用户配置文件可以登录网站:如果我们将继承属性设置为“Namespace.Website.NamespaceA.CustomProfileA,Namespace.Website”,则只有profileA能够登录到其域,如果我们将其设置为“Namespace.Website.NamespaceB.CustomProfileB,Namespace.Website” profileB 将能够登录其域,因为切换器将使用此域。

网络上的所有文章都描述了如何为一个自定义用户配置文件设置自定义用户配置文件、切换器和switchingProviders,但没有适合我的案例的示例。

谢谢,斯尔詹

最佳答案

不幸的是,似乎没有一种干净的方法可以让 API 为您创建多个用户配置文件类。通常,您将通过 Sitecore.Context.User.Profile 获取用户配置文件。 Context 类是静态的,初始化 Profile 属性的方法是私有(private)的,因此没有地方可以插入额外的逻辑。

但是,您可以为配置文件创建包装类。从这样的基类开始:

public abstract class CustomProfileBase
{
public CustomProfileBase(Sitecore.Security.UserProfile innerProfile)
{
Assert.ArgumentNotNull(innerProfile, nameof(innerProfile));
InnerProfile = innerProfile;
}

public Sitecore.Security.UserProfile InnerProfile { get; protected set; }

public virtual string GetCustomProperty(string propertyName)
{
return InnerProfile.GetCustomProperty(propertyName);
}

public virtual void SetCustomProperty(string propertyName, string value)
{
InnerProfile.SetCustomProperty(propertyName, value);
}

public virtual void Save()
{
InnerProfile.Save();
}

public virtual string Email
{
get { return InnerProfile.Email; }
set { InnerProfile.Email = value; }
}

// Other members omitted for brevity
}

CustomProfileBase 类将有一个成员来包装Sitecore.Security.UserProfile 的每个公共(public)成员。然后,您将创建您的站点特定配置文件,如下所示:

public class SiteOneProfile : CustomProfileBase
{
public SiteOneProfile(UserProfile innerProfile) : base(innerProfile)
{
}

public string CustomPropertyOne
{
get { return GetCustomProperty("CustomPropertyOne"); }
set { SetCustomProperty("CustomPropertyOne", value); }
}
}

然后您可以从 Controller 或其他地方使用它,如下所示:

var profile = new SiteOneProfile(Sitecore.Context.User.Profile);
model.property = profile.CustomPropertyOne;

更新

使用此方法时,您只需将配置中的继承属性保留为默认值即可。此外,配置文件不应影响登录能力。如果您仍然遇到问题,请使用登录时出现的错误的详细信息更新您的问题。

关于Sitecore 多个自定义用户配置文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37341648/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com