【发布时间】:2016-04-15 01:40:16
【问题描述】:
我想自定义不匹配的404页面,我在路由器“all”中将“模板”参数指定为“{*}”,旨在捕获所有不匹配的url(例如“http://localhost:12345/aaa/bbb/ccc/ddd/”) “默认”路由器。有什么办法吗?
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" });
});
【问题讨论】:
-
MVC 6 404 Not Found的可能重复
标签: asp.net-mvc routing