Umbraco - 从文本而不是 nodeId 获取内容

Umbraco - Get Content from text instead of nodeId

目前我的项目中有以下代码:

var umbracoHelper = new UmbracoHelper(UmbracoContext.Current);
IPublishedContent currentContent = umbracoHelper.TypedContent(UmbracoContext.Current.PageId);
var contentService = UmbracoContext.Current.Application.Services.ContentService;

int configPageId = 0;

if(currentContent.AncestorsOrSelf().Select(x => x.Id).ToArray().Contains(1309))
{
    configPageId = 1872;
} 
else if(currentContent.AncestorsOrSelf().Select(x => x.Id).ToArray().Contains(1308))
{
    configPageId = 1660;
}
if(configPageId != 0)
{
    IContent content = contentService.GetById(configPageId);
    linkCreditSimulator = content.GetValue("linkCreditSimulator").ToString();
    linkAskNow = content.GetValue("linkAskNow").ToString();
}

我认为无论是谁做的,都是由于不同的环境具有不同的 id。

我希望将其正常化。

如果我运行下面的查询:

    SELECT TOP (1000)  d.text
  FROM [cmsContent] c
  LEFT join cmsContentXml cxml on c.nodeId = cxml.nodeId
  LEFT join cmsMedia m on m.nodeId = c.nodeId
  LEFT join cmsDocument d on d.nodeId = c.nodeId
  LEFT join cmsMedia cm on cm.nodeId = c.nodeId
  LEFT join cmsMember mb on mb.nodeId = c.nodeId
  LEFT join cmsPreviewXml p on p.nodeId = c.nodeId
  LEFT join cmsTagRelationship tr on tr.nodeId = c.nodeId
  where c.nodeId = 1872

我得到值“Simulator”,它在不同环境中都是相同的。

我试图在 contentService 中找到任何类似于

的方法
IContent content = contentService.GetByName("Simulator");

但是我做不到。你知道是否有办法实现这一目标? 您会推荐什么其他方法?

此致

假设“configPage”是一个特定的内容类型,您可以使用其别名查询该类型:https://our.umbraco.com/documentation/Reference/Querying/UmbracoHelper/#contentatxpathstring-xpath - 这样您只需要硬编码别名而不是一堆 ID,如你说,可以而且将会区分环境。

ContentService 的使用也应保持在最低限度,因为它使用数据库访问(就像您示例中的巨大 SQL 查询)而不是缓存。 ContentAtXPath 使用缓存。