There are several ways of implementing the wildcard pages. A wildcard item in Sitecore is a way to create dynamic URLs that pass data through the URL instead of relying on query string values. The name of a wildcard item must be the wildcard character (*), and it matches any item name on the same level as the wildcard item. For example, if the product name is “product-1”, its URL would be http://domain/products/product-1.
So directly coming to the point. I personally used 2 ways of handling the wildcard pages.
- Using item resolver, or
- Using rendering data source resolver.
Using item resolver
If it doesn't work after this then reason can be following:
<mvc.getPageItem patch:source="Sitecore.Mvc.config">
<processor type="Sitecore.Mvc.Pipelines.Response.GetPageItem.SetLanguage, Sitecore.Mvc"/>
<processor type="Sitecore.Mvc.Pipelines.Response.GetPageItem.GetFromRouteValue, Sitecore.Mvc"/>
<processor type="Sitecore.Mvc.Pipelines.Response.GetPageItem.GetFromRouteUrl, Sitecore.Mvc"/>
<processor type="Sitecore.Mvc.Pipelines.Response.GetPageItem.GetFromOldContext, Sitecore.Mvc"/>
<processor type="Sitecore.ContentTesting.Mvc.Pipelines.Response.GetPageItem.PageLevelTestVariantResolver, Sitecore.ContentTesting.Mvc" patch:source="Sitecore.ContentTesting.Mvc.config"/>
<processor type="Sitecore.ContentTesting.Mvc.Pipelines.Response.GetPageItem.ContentTestVariantResolver, Sitecore.ContentTesting.Mvc" patch:source="Sitecore.ContentTesting.Mvc.config"/>
</mvc.getPageItem>
Recommedation
Create a processor for this pipeline that comes after either GetFromRouteUrl or GetFromOldContext to determine whether you want to continue using the Page Item found, or use from the Custom Item Resolver.
Or
The really simple solution to resolve this issue is to reorder the processors within the mvc.getPageItem pipeline so that GetFromOldContext always comes after the SetLanguage processor.
<sitecore>
<pipelines>
<mvc.getPageItem>
<processor type="Sitecore.Mvc.Pipelines.Response.GetPageItem.GetFromOldContext, Sitecore.Mvc">
<patch:delete />
</processor>
<processor patch:after="processor\[@type='Sitecore.Mvc.Pipelines.Response.GetPageItem.SetLanguage, Sitecore.Mvc'\]" type="Sitecore.Mvc.Pipelines.Response.GetPageItem.GetFromOldContext, Sitecore.Mvc"/>
</mvc.getPageItem>
</pipelines>
</sitecore>
namespace YourNamespace
{
using System.Web.Routing;
using Sitecore.Data.Items;
using Sitecore.Mvc.Pipelines.Request.RequestBegin;
using Sitecore.Mvc.Presentation;
public class SetupPageContext : Sitecore.Mvc.Pipelines.Request.RequestBegin.SetupPageContext
{
protected override PageContext CreateInstance(RequestContext requestContext, RequestBeginArgs args)
{
return new PageContextFixed
{
RequestContext = requestContext
};
}
}
public class PageContextFixed : PageContext
{
protected override Item GetItem()
{
// Assumption: If you have a Context.Item you have to have a Context.Language
return Sitecore.Context.Item ?? base.GetItem();
}
}
}
And the configuration:
<sitecore>
<pipelines>
<mvc.requestBegin>
<processor patch:instead="processor\[@type='Sitecore.Mvc.Pipelines.Request.RequestBegin.SetupPageContext, Sitecore.Mvc'\]" type="Example.SetupPageContext,Example" />
</mvc.requestBegin>
</pipelines>
</sitecore>
https://sitecorepeanuts.blogspot.com/2024/03/wildcard-page-in-sitecore.html
ReplyDelete