我正在使用Sitecore.NET 6.4.1构建的银行现有网站,我遇到了一些别名问题。他们使用别名为银行家的个人页面设置更友好的URL。例如:www.domain.com/bankername解析为www.domain.com/About/People/Banker-ID。我遇到的问题是链接到实际页面的别名页面不会继承该部分中的所有元数据。因此,我获得了所有站点范围的默认元标记,而不是个人银行家的个性化元标记(即标题中的银行家名称)。元数据在实际银行家页面上设置,并在访问www.domain.com/About/People/Banker-ID时正常工作。
除了链接页面的页面内容之外,还有办法让别名继承元数据吗?
public List<string> getmetaDetails()
{
List<string> metaDetails = new List<string>();
string metaTitle = String.Empty;
string metaDesc = String.Empty;
string metaKeyword = String.Empty;
try
{
// get root home item
Sitecore.Data.Items.Item homeItem = Sitecore.Context.Database.GetItem("/sitecore/content/Home");
Sitecore.Data.Items.Item Item = homeItem;
// get Page array by url
string pageUrl = Sitecore.Web.WebUtil.GetRawUrl().TrimStart('/');
string[] pageArr = pageUrl.Split('/');
//Removes '?...' after the actual path.
for(int i=0; i<pageArr.Length; i++)
if (pageArr[i].Contains("?")) pageArr[i] = pageArr[i].Substring(0, pageArr[i].LastIndexOf('?'));
if (pageArr[0] == "Advice")
{
Sitecore.Data.Items.Item AdviceItem = Sitecore.Context.Database.GetItem("/sitecore/content/Home/Advice");
if (AdviceItem != null)
{
metaTitle = FieldRenderer.Render(AdviceItem, "Meta Title");
metaDesc = FieldRenderer.Render(AdviceItem, "Meta Description");
metaKeyword = FieldRenderer.Render(AdviceItem, "Meta Keywords");
}
if (pageArr.Length > 1)
{
if(!String.IsNullOrEmpty(pageArr[1]))
{
Feeds feed = new Feeds();
List<FeedItem> adviceFeed = new List<FeedItem>();
string sql = "SELECT * FROM `web_feeds` WHERE url='" + pageArr[1] + "'";
adviceFeed = feed.getFeedFromDB(sql);
if(adviceFeed.Count >0)
{
metaTitle = adviceFeed[0].title;
metaDesc = adviceFeed[0].description;
metaKeyword +=","+ adviceFeed[0].tag;
}
}
}
}
else
{
// loop threw page array to find the item
foreach (string page in pageArr)
{
Item = getCurrentHomeItem(page, Item);
if (Item != null)
{
metaTitle = FieldRenderer.Render(Item, "Meta Title");
metaDesc = FieldRenderer.Render(Item, "Meta Description");
metaKeyword = FieldRenderer.Render(Item, "Meta Keywords");
}
}
}
if (String.IsNullOrEmpty(metaTitle)) metaTitle = FieldRenderer.Render(homeItem, "Meta Title");
if (String.IsNullOrEmpty(metaDesc)) metaDesc = FieldRenderer.Render(homeItem, "Meta Description");
if (String.IsNullOrEmpty(metaKeyword)) metaKeyword = FieldRenderer.Render(homeItem, "Meta Keywords");
}
catch (Exception ex)
{
metaTitle = DEFAULT_TITLE;
metaDesc = DEFAULT_DESC;
metaKeyword = DEFAULT_KEYWORDS;
}
metaDetails.Add(metaTitle);
metaDetails.Add(metaDesc);
metaDetails.Add(metaKeyword);
return metaDetails;
}
答案 0 :(得分:0)
这是我为那些感兴趣的人提出的解决方案。
if (Sitecore.Configuration.Settings.AliasesActive &&
Sitecore.Context.Database.Aliases.Exists(HttpContext.Current.Request.RawUrl))
{
//Is an alias
Item targetItem = Sitecore.Context.Database.GetItem(Sitecore.Context.Database.Aliases.GetTargetID(HttpContext.Current.Request.RawUrl));
metaTitle = FieldRenderer.Render(targetItem, "Meta Title");
metaDesc = FieldRenderer.Render(targetItem, "Meta Description");
metaKeyword = FieldRenderer.Render(targetItem, "Meta Keywords");
}