首页 新闻 会员 周边

ASP.NET Core 路由模板包含连字符的问题

0
悬赏园豆:30 [已解决问题] 解决于 2024-01-05 20:12

下面的 ASP.NET Core 路由模板(route template)中这样包含 - 连字符(hyphen)

[Route("/{blogApp}/{postType}/-/{**slug}")]

运行时报错

Microsoft.AspNetCore.Routing.Patterns.RoutePatternException: The route template separator character '/' cannot appear consecutively. It must be separated by either a parameter or a literal value.
   at Microsoft.AspNetCore.Routing.Patterns.RoutePatternParser.Parse(String pattern)

请问如何解决这个问题?

dudu的主页 dudu | 高人七级 | 园豆:30943
提问于:2024-01-05 19:50
< >
分享
最佳答案
0

汗,弄错了,这个 route template 没有问题,是另外一个 route template 中包含了 //

可以通过下面的测试代码避免这个问题

RoutePatternFactory.Parse(template).Should().NotBeNull();
dudu | 高人七级 |园豆:30943 | 2024-01-05 20:12
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册