'Is it possible to specify the 'default' routing for unmatched request path?
Like in nginx, where when no location is matched, it can route the request path as per the defined default section. Something like MapElse method.
Solution 1:[1]
One way is to make a route that catches anything;
Order parameter - by default all routes have Order = 0. Hence setting Order = 10 will make this last (be sure to update this if you will have another route with Order 10).
The asterisk in the route parameter means it would catch the entire url as a string hence you could split it by /
[Route("{*url}", Order = 10)]
public IActionResult Handle404(string url)
{
// say sample.com/test/1/edit
// it would catch `test/1/edit`
foreach(string item in url.Split("/")) {
...
}
Response.StatusCode = 404;
return View();
}
There are also other methods mentioned here but you need to make code logic that would handle status codes; How to handle Custom Errors With .Net Core 2.2 MVC
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 |
