.Net core路由高级用法

先说startup中的路由

这里是我们现在用的默认路由,但是在使用当中也有麻烦。总而言之 用的不爽。

使用属性路由:RouteAttribute特性

默认的HomeController下面的Index访问url路径是: home/index

但是有时候我不想这么干我就想装个B咋办

ok很简单index代码更改如下

        [Route("zhuangb/index")]
        public IActionResult Index()
        {
            return View();
        }

这样就可以访问 zhuangb/index了

标记替换

可以使用标记替换

路由模板参数

https://docs.microsoft.com/zh-cn/aspnet/core/fundamentals/routing?view=aspnetcore-2.1#route-template-reference

原文地址:https://www.cnblogs.com/Extnet/p/9961962.html