Main  /  Edit version 2  /  Edit version 3  /   /  Users Area

Difference "Customize your "Page not found | 404" page" ver. 2 versus ver. 3

Content:

By default application::main() returns a 404 page if it does not find any dispatcher for a given url:
void application::main(std::string url) {
if(!dispatcher().dispatch(url)) {
response().make_error_response(http::response::not_found);
}
}
To create your own 404 page, you must override the default application::main().
void myApplication::main(std::string url) {
if (!dispatcher().dispatch(url)) {
// Set the 404 status.
response().status(http::response::not_found);
response().out() << "Page not found";
}
}
Or you can use your own [template](/wikipp/en/page/cppcms_1x_templates):
void myApplication::main(std::string url) {
if (!dispatcher().dispatch(url)) {
// Set the 404 status.
response().status(http::response::not_found);
content::main c; // Your main template.
// c.content and c.title are defined in your template.
c.content = "Use the search box.";
c.title = "Page not found";
render("main", c);
}
}
By default application::main() returns a 404 page if it does not find any dispatcher for a given url:
void application::main(std::string url) {
if(!dispatcher().dispatch(url)) {
response().make_error_response(http::response::not_found);
}
}
To create your own 404 page, you must override the default application::main().
void myApplication::main(std::string url) {
if (!dispatcher().dispatch(url)) {
// Set the 404 status.
response().status(http::response::not_found);
response().out() << "Page not found";
}
}
Or you can use your own [template](/wikipp/en/page/cppcms_1x_templates):
void myApplication::main(std::string url) {
if (!dispatcher().dispatch(url)) {
// Set the 404 status.
response().status(http::response::not_found);
content::main c; // Your main template.
// c.content and c.title are defined in your template.
c.content = "Use the search box.";
c.title = "Page not found";
render("main", c);
}
}

Sidebar:

← [How to run the application at the root of the web server](http://cppcms.com/wikipp/en/page/run_application_web_server_root)
[Encoding and UTF-8](http://cppcms.com/wikipp/en/page/cppcms_1x_encoding_and_utf8)→

About

CppCMS is a web development framework for performance demanding applications.

Support This Project

SourceForge.net Logo

Поддержать проект

CppCMS needs You


Navigation

Main Page


Valid CSS | Valid XHTML 1.0