In DD4T the 404 page can be retrieved as below, Override the Action Page, and when the Page is null return the NotFound Action. In the NotFound action, Query the Broker for the 404 page and return the view.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class PageController : TridionPageController | |
{ | |
public override ActionResult NotFound() | |
{ | |
var page = ContentProvider.GetPageModel(WebRequestContext.Localization.Path + "/404.aspx"); | |
if (page == null) | |
{ | |
throw new HttpException(404, "Page Not Found"); | |
} | |
Response.StatusCode = 404; | |
return View("Error", page); | |
} | |
public override ActionResult Page(string pageUrl) | |
{ | |
var page = ContentProvider.GetPageModel(pageUrl); | |
if (page == null) | |
{ | |
return NotFound(); | |
} | |
//TODO:--- | |
} | |
public ActionResult ServerError() | |
{ | |
Response.StatusCode = 500; | |
return View("ServerError"); | |
} | |
} |
The 500 Error page can be throw from the Global level as below, when error occurred handle it the global level and return just view with error information
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class MvcApplication : NinjectHttpApplication | |
{ | |
protected void Application_Error(object sender, EventArgs e) | |
{ | |
if (Context.IsCustomErrorEnabled) | |
ShowCustomErrorPage(Server.GetLastError()); | |
} | |
private void ShowCustomErrorPage(Exception exception) | |
{ | |
HttpException httpException = exception as HttpException; | |
if (httpException == null) | |
httpException = new HttpException(500, "Internal Server Error", exception); | |
RouteData routeData = new RouteData(); | |
Logger.Error("500 - Internal Server Error {0}", httpException); | |
routeData.Values.Add("controller", "Page"); | |
routeData.Values.Add("action", "ServerError"); | |
Server.ClearError(); | |
IController controller = DependencyResolver.Current.GetService<PageController>(); ; | |
controller.Execute(new RequestContext(new HttpContextWrapper(Context), routeData)); | |
} | |
} |
0 comments:
Post a Comment