locked
404 view in ASP.NET MVC without IIS settings RRS feed

  • Question

  • User38624581 posted

    Is it possible to create a final route that catches all .. and bounces the user to a 404 view in ASP.NET MVC?

    Thursday, May 10, 2018 5:43 PM

Answers

  • User-1134632663 posted

    For the global.asax, just add this code as your last route to register:

    routes.MapRoute(
        "404-PageNotFound",
        "{*url}",
        new { controller = "StaticContent", action = "PageNotFound" }
        );

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, May 10, 2018 5:44 PM

All replies

  • User-1134632663 posted

    For the global.asax, just add this code as your last route to register:

    routes.MapRoute(
        "404-PageNotFound",
        "{*url}",
        new { controller = "StaticContent", action = "PageNotFound" }
        );

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, May 10, 2018 5:44 PM
  • User38624581 posted

    but I don't want to set this up in my IIS settings.

    Thursday, May 10, 2018 5:45 PM
  • User-1134632663 posted

    yes t will work....

    Thursday, May 10, 2018 5:45 PM