I have some links on my page for which the controllers are yet to be created. I have my custom controller factory like this:
public class MyControllerFactory : DefaultControllerFactory
{
public override IController CreateController(RequestContext requestContext, string controllerName)
{
try
{
IController controller = base.CreateController(requestContext, controllerName);
HttpContext.Current.Items["Controller"] = controller;
return controller;
}
catch { return null; }
}
}
This works fine as long as it can find controller. However I throws yellow screen of death if I return null from my method. How can I gracefully handle this? I want to redirect to some page along with 404 nicely formatted message or maybe show some message such as “In Progress”.
Did you try adding this?
[HandleError(ExceptionType = typeof(NullReferenceException), Order = 1, View = "NotFound")]you will have to add a NotFound view to the shared views folder. Annotate your controller factory with this attribute.