ASP.NET MVC - URL Slug 的正则表达式
我正在编写一个用于路由的 URL Slug。我应该将段塞约束留空还是什么?
这是我的代码:
routes.MapRoute(
null,
"q/{slug}/{id}",
new { controller = "q", action = "Index" },
new { id = @"^(\{){0,1}[0-9a-fA-F]{8}\-[0-9a-fA-F]{4}\-[0-9a-fA-F]{4}\-[0-9a-fA-F]{4}\-[0-9a-fA-F]{12}(\}){0,1}$" }
);
slug 将采用这种格式
how_do_you_open_jar_file_on_computer
I am writing a URL Slug for routing. Should I leave the slug constraint blank or what?
Here is my code:
routes.MapRoute(
null,
"q/{slug}/{id}",
new { controller = "q", action = "Index" },
new { id = @"^(\{){0,1}[0-9a-fA-F]{8}\-[0-9a-fA-F]{4}\-[0-9a-fA-F]{4}\-[0-9a-fA-F]{4}\-[0-9a-fA-F]{12}(\}){0,1}$" }
);
The slug will be in this format
how_do_you_open_jar_file_on_computer
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我会把它留空。我会将其留给控制器中的操作来确定其是否有效。这样您就可以轻松抛出 404 错误或重定向到默认页面。
I would leave it blank there. I would leave it up to the Action in the Controller to determine if its valid or not. That way you can easily throw 404 errors or redirect to default pages.