Main  /  Edit  /  History  /   /  Users Area

Customize your "Page not found | 404" page

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:

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 | Top | Encoding and UTF-8

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