Skip to content

Instantly share code, notes, and snippets.

@steliodibello
Last active November 23, 2023 16:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save steliodibello/839faed9f90c220d739d2cad9b2fcbb3 to your computer and use it in GitHub Desktop.
Save steliodibello/839faed9f90c220d739d2cad9b2fcbb3 to your computer and use it in GitHub Desktop.
namespace XXXX.Controllers
{
using Microsoft.AspNetCore.Mvc;
using Sitecore.AspNet.RenderingEngine;
using Sitecore.LayoutService.Client.Exceptions;
public class SitecoreController : Controller
{
public IActionResult Index()
{
var request = HttpContext.GetSitecoreRenderingContext();
if (request == null || request.Response == null)
{
return new EmptyResult();
}
//Check if layout service call return any error
if (request.Response.HasErrors)
{
//loop through errors
foreach (var error in request.Response.Errors)
{
switch (error)
{
//this is the case of 404 errors
case ItemNotFoundSitecoreLayoutServiceClientException _:
Response.Redirect("/404");
break;
}
}
}
return View();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment