如何将类似Wordpress的URL定义为Razor页面路由?

时间:2018-06-18 07:37:26

标签: c# razor asp.net-core asp.net-core-2.0

我想"复制"用于在ASP.NET Core 2.1 Razor页面中实现的博客的Wordpress博客网址。但是,我不确定如何正确/有效地制作它,也不确定它是否可行。

Wordpress博客网址通常如下:

root/ - the first page of a list of posts
root/page/2 - the second page of a list of posts

root/2017 - the first page of a list of posts published in 2017
root/2017/page/2 - the second page of a list of posts published in 2017

root/2017/02 - the first page of a list of posts published in February 2017
root/2017/02/page/2 - the second page of a list of posts published in February 2017

root/2017/02/we-are-here - the specific blog post (published in February 2017)

如何使用有意义数量的路径规则和物理页面和页面模型文件正确制作它?它是否合理可行(没有针对每个变体的规则)?

例如,我不知道如何在@page中表达它应该匹配除特定博客帖子以外的所有内容。例如,将以下两个部分组合在一个Razor页面文件中:

@page "{year:int:range(2000,2100)?}/{month:int:range(1,12)?}"
@page "{year:int:range(2000,2100)?}/{month:int:range(1,12)?}/page/{page:int:min(1)}"

0 个答案:

没有答案