Difference "Customize your "Page not found | 404" page" ver. 3 versus ver. 4
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);
|
|
}
|
}
|
|
---
|
|
|
← [How to run the application at the root of the web server][prev]
|
| [Top](#maincontent)
|
| [Encoding and UTF-8][next] →
|
|
[prev]: /wikipp/en/page/run_application_web_server_root
|
[next]: /wikipp/en/page/cppcms_1x_encoding_and_utf8 |
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)→ |
|
|
## Browse
|
|
[CppCMS 1.x.x - Stable][toc]
|
|
← [How to run the application at the root of the web server][prev]
|
[Encoding and UTF-8][next] →
|
|
[toc]: /wikipp/en/page/cppcms_1x
|
[prev]: /wikipp/en/page/run_application_web_server_root
|
[next]: /wikipp/en/page/cppcms_1x_encoding_and_utf8 |
About
CppCMS is a web development framework for performance demanding applications.
Support This Project
Navigation
Main Page
Valid CSS
| Valid XHTML 1.0