I was tasked with trying to set up a simple static cshtml page that would avoid the yellow screen sent by the .net framework.
I built a class library that has a controller and a view.
controller:
public class ErrorHandlerController : Controller
{
public ActionResult ErrorPage()
{
return View();
}
}
Simple View:
<header id="siteHeader">
<div class="logo">
<a href="/"></a>
</div>
</header>
You have reached this page in error!!
<footer>
<div class="wrapper">
<div class="logo">
<div class="copyright">
<p>@Model.CopyRight.CopyrightText.Replace("_YEAR_", DateTime.Now.Year.ToString())</p>
</div>
</div>
</div>
</footer>
and in the web.config
<customErrors mode="On" defaultRedirect="/ErrorHandler/ErrorPage" />
I then tried to access the page, but received a 404 error.
Since this is an inherited project, I then set up this config file:
public class RouteLoader
{
public void Process(PipelineArgs args)
{
HttpConfiguration config = GlobalConfiguration.Configuration;
SetRoutes(config);
var cors = new EnableCorsAttribute("*", "*", "*");
config.EnableCors(cors);
SetSerializerSettings(config);
}
private void SetRoutes(HttpConfiguration config)
{
config.Routes.MapHttpRoute("Error Page", "ErrorHandler/ErrorPage", new { action = "ErrorPage", controller = "ErrorHandler" });
}
private void SetSerializerSettings(HttpConfiguration config)
{
JsonSerializerSettings settings = new JsonSerializerSettings { ContractResolver = new DefaultContractResolver() };
config.Formatters.JsonFormatter.SerializerSettings = settings;
config.Formatters.Remove(config.Formatters.XmlFormatter);
config.EnsureInitialized();
}
}
This is how the pipeline is initialized:
<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/" xmlns:set="http://www.sitecore.net/xmlconfig/set/" xmlns:role="http://www.sitecore.net/xmlconfig/role/">
<sitecore>
<pipelines>
<initialize>
<processor type="Berry.Feature.ErrorHandler.Pipeline.RouteLoader, Berry.Feature.ErrorHandler" />
</initialize>
</pipelines>
</sitecore>
</configuration>
And now I get the following page:
{"Message":"No HTTP resource was found that matches the request URI 'https://berrysc.dev.local/ErrorHandler/ErrorPage"}
I think everything is in place, but I am just not certain. Is there anything I should check for.