在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访问到,实现伪静态

相关文章:

  • 2022-01-05
  • 2022-12-23
  • 2021-07-03
  • 2021-10-26
  • 2022-02-02
  • 2022-12-23
猜你喜欢
  • 2021-10-16
  • 2021-06-25
  • 2022-12-23
  • 2022-12-23
  • 2021-08-13
  • 2021-05-24
相关资源
相似解决方案