0

I want to custom unmatched 404 page, I specified the "template" parameter as "{*}" in router "all", aiming to catch all urls (such as "http://localhost:12345/aaa/bbb/ccc/ddd/") that are not matching to the "default" router. Is there any way to do so?

app.UseMvc(routes =>
        {
            routes.MapRoute(
                name: "default",
                template: "{Controller:regex((?i)^((?!Error).)*$)}/{Action}/{id?}",
                defaults: new { Controller = "Home", Action = "Index" })

            //TODO: This Route is not working as expected.
            .MapRoute(
                name: "all",
                template: "{*}", //<---------
                defaults: new { Controllers = "Error", Action = "Unknown" });
        });
Peng Du
  • 51
  • 5

1 Answers1

0

You can try it like this "{*url}" or "/{*url}". I think it needs something after a wildcard so you could use the caught url as a parameter.

Dainius Lukša
  • 966
  • 1
  • 11
  • 22