【发布时间】:2019-09-05 21:23:11
【问题描述】:
如果地址格式正确,一切都很好。 但是当我在地址栏中输入随机字符串时,asp net core 路由到同一个控制器,特别是 Index(model)
[HttpGet]
public IActionResult Index() { ... }
[HttpGet({model})]
public IActionResult Index(ViewModel model) { ... }
而不是返回 404 Not found。 是控制器有问题吗?
【问题讨论】:
-
你在地址栏中的哪个位置输入这个随机字符串?
-
而目标控制器不是HomeController
-
您是否有
redirect用于错误或默认?这可能是自定义 404 页面的意外。 -
[HttpGet({model})]错误,改成[HttpGet]。模型不能是 url 的一部分,因为它是一个复杂的类型。当普通路由无法处理请求时,会回退到该方法,但无法序列化模型。
标签: asp.net-mvc asp.net-core routing