在MVC的逻辑代码里,Controller和Action是必须的,但是在网址里,并不需要完全体现Controller和Action。比如我们经常希望看到http://localhost/About而不是http://localhost/Home/About。
我们可以利用Route属性定义自己的路由规则
定义短网址
[Route("about")] [Route("about.html")] public IActionResult About() { return View(); }
这样就可以通过http://localhost/About或者http://localhost/About.html访问到,实现伪静态