sitecore - 如何找出项目与哪个 Sitecore 站点相关联?

标签 sitecore

我们有一个多站点解决方案(站点 1 和站点 2),我需要能够确定我们获取 URL 的项目(在自定义的 LinkProvider 中)是否属于当前上下文站点( Sitecore.Context.Site ),或者是其他站点的一部分。有没有好的方法来做到这一点?

基本上,我们只需要能够找出该项目与哪个站点相关联。我们可以将该值与当前上下文站点进行比较。

最佳答案

/// <summary>
/// Get the site info from the <see cref="SiteContextFactory"/> based on the item's path.
/// </summary>
/// <param name="item">The item.</param>
/// <returns>The <see cref="SiteInfo"/>.</returns>
public static SiteInfo GetSiteInfo(this Item item)
{
  return SiteContextFactory.Sites
    .Where(s => !string.IsNullOrWhiteSpace(s.RootPath) && item.Paths.Path.StartsWith(s.RootPath, StringComparison.OrdinalIgnoreCase))
    .OrderByDescending(s => s.RootPath.Length)
    .FirstOrDefault();
}

关于sitecore - 如何找出项目与哪个 Sitecore 站点相关联?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14200864/

相关文章:

sitecore - 如何访问 sitecore 中的下拉列表字段类型所选值

asp.net - 使用 ASPXAUTH cookie 和 asp.net_sessionID cookie 控制用户 session

ssl - 站点核心 ECM : Could not establish trust relationship for the SSL/TLS secure channel

sitecore - 如何让 Lucene.NET 将 2 个 Sitecore 字段合并为 1 个索引字段?

solr - 何时在Sitecore 7版本中绝对在Lucene上使用SOLR?

c# - 如何将自定义标记放在 sitecore sc 字段中?

c# - 迭代 Sitecore 存储桶项目

c# - 在发布 :end event 中获取选择发布的语言

powershell - Sitecore powershell 搜索所有包含该关键字的项目

sitecore - 如何在 Sitecore 内容交付服务器上重建自定义 Lucene 索引?