Monday, 4 November 2013

Sitecore: Default Pages showing the home page

Default pages in Sitecore renders home page of the site.


Though there is no Sitecore item with name default, the above links still render the 
StartPath. Ideally this should redirect to 404 error page.

Sitecore DefaultResolver Pipeline checks for this default document and if the request is with the default document, then it set the current context item as the Site StartPath item and we get the StartPath for all the above URLs.

Sitecore.Pipelines.HttpRequest.DefaultResolver

SiteContext site = Context.Site;
if ((((Context.Item == null) && (Context.Database != null)) && ((site != null) && (site.StartPath.Length != 0))) && ((args.LocalPath.Length == 0) || (args.LocalPath == "/default")))
{
    Item item = args.GetItem(site.StartPath);
    if (item != null)
    {
        Tracer.Info("Using default item \"" + site.StartPath + "\" from site definition.");
        Context.Item = item;
    }
    else if (!args.PermissionDenied)
    {
        Tracer.Error("Default item was not found: " + site.StartPath, "Database: \"" + Context.Database.Name + "\"");
    }
}

To avoid this, create a custom DefaultResolver pipeline and remove the condition for the default document.
if ((((Context.Item == null) && (Context.Database != null)) && ((site != null) && (site.StartPath.Length != 0))) && ((args.LocalPath.Length == 0)

This will throw 404 error for all the default URLs.

1 comment:

  1. Interesting, never really looked into what the default resolver was, thanks for sharing.

    ReplyDelete

Articles

Sitecore 9.3 released!

Sitecore 9.3 has the Solr 8.1.1 support (Sitecore compatibility table is yet to be updated). SIF 2.2.0 Got a new editor - The Horizon edi...