How to check whether Sitecore item is using alias

假如想象 提交于 2019-11-30 21:23:46

I would rely on the Context.Database.Aliases.Exists(path) in your case. Also, it seems to be a good idea to check whether the aliases are active in the web.config: Sitecore.Configuration.Settings.AliasesActive.

What we have done in the past is when an alias is used to set a canonical url link in the head of the page.
For example if you have /food alias pointing to /news/food when you go to the /food you'll put <link href="http://[websiteurl]/news/food" rel="canonical" /> in the <head> of the page.

EDIT:

Here is another way

public class AliasResolver : Sitecore.Pipelines.HttpRequest.AliasResolver
{
    public override void Process(HttpRequestArgs args)
    {
        base.Process(args);

        if (Context.Item != null)
        {
            args.Context.Items["CanonicalUrl"] = Context.Item.GetFullUrl(args.Context.Request.Url);
        }
    }
}

Then in your header control all you need to do is check whether HttpContext.Current.Items["CanonicalUrl"] is set and display it.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!