I am having a PageUnavailableProcessor
, which extends GetPageItemProcessor
. This Processor helps in redirecting to a user-defined Page for all 403
errors (we are tagging the pages by language and location). So far so good. Now, we need the redirect to the actual page when the user changes/ corrects the tagging.
So we thought of adding a session variable and store the Original ItemId when the user selects wrong tagging and need to retrieve the same from session variable when the user selects/corrects tagging. The below is the code.
public class PageUnavailableProcessor : GetPageItemProcessor
{
public readonly BaseClient _baseClient;
public PageUnavailableProcessor(BaseClient baseClient) : base(baseClient)
{
_baseClient = baseClient;
}
public override void Process(GetPageItemArgs args)
{
Assert.ArgumentNotNull(args, nameof(args));
var httpRequest = HttpContext.Current?.Request;
var path = HttpContext.Current.Request.Path;
var originalRequest = Context.Database.GetItem(path);
if (originalRequest != null)
{
var originalRequestGuid = originalRequest.ID;
HttpContext.Current.Session.Add("OriginalItemId", originalRequestGuid);
}
}
}
I am sure that the session variable is storing correctly (in above) but always returning null when trying to retrieve the session variable in service layer.
if (HttpContext.Current.Session["OriginalItemId"] != null)
{......}
when browsed for similar issues, many asked to check the sequence of processors and I can confirm that they look good as shown below.
<mvc.getPageItem patch:source="Sitecore.Mvc.config">
<processor type="Sitecore.Mvc.Pipelines.Response.GetPageItem.SetLanguage, Sitecore.Mvc" resolve="true"/>
<processor type="Sitecore.Mvc.Pipelines.Response.GetPageItem.GetFromAlias, Sitecore.Mvc" resolve="true"/>
<processor type="Sitecore.Mvc.Pipelines.Response.GetPageItem.GetFromRouteValue, Sitecore.Mvc" resolve="true"/>
<processor type="Sitecore.XA.Feature.ErrorHandling.Pipelines.GetPageItem.GetErrorPageContextItem, Sitecore.XA.Feature.ErrorHandling" resolve="true" patch:source="Sitecore.XA.Feature.ErrorHandling.config"/>
<processor type="Sitecore.Mvc.Pipelines.Response.GetPageItem.GetFromRouteUrl, Sitecore.Mvc" resolve="true"/>
**<processor type="MyNamespace.Web.Pipelines.PageUnavailableProcessor, MyNamespace.Web" resolve="true" patch:source="Pipeline.PageUnavailable.config"/>**
<processor type="Sitecore.Mvc.Pipelines.Response.GetPageItem.GetFromOldContext, Sitecore.Mvc" resolve="true"/>
</mvc.getPageItem>
Any ideas or thoughts why the session is null/empty?