Content/Page Umbraco 中的结构

Content/Page structure in Umbraco

我在 MVC 中使用 Umbraco。

我在 MVC umbraco 中创建了一个使用查询字符串参数的动态页面

http://www.example.com/City?id=1&type=9
http://www.example.com/City?id=5&type=6
http://www.example.com/City?id=6&type=4

在 Umbraco 中,我有一个名为 City 的内容页面(连同它的 DocumentType 和模板),在我的 MVC 项目中,Controller 和 Action Method 的名称是 City 和 City(action 方法采用参数 id 和 type)。

现在我需要创建多个页面来共享页面 "City" 的功能,例如

http://www.example.com/City/A?id=1&type=9
http://www.example.com/City/B?id=5&type=6
http://www.example.com/City/C?id=6&type=4

这些页面中的每一个都需要显示相同的动态内容,具体取决于 Querystring 参数以及我希望由 CMS 管理的一些修复内容。

如何在 Umbraco 中创建以上页面? 如何创建上面的Url? 如何在我原来的 "City"" 页面中分享代码?

我是 Umbraco 的新手,所以请指教。

您应该阅读有关路由劫持的文档:https://our.umbraco.org/documentation/reference/routing/custom-controllers

网络上也有不少教程和博客文章处理这类事情,所以值得搜索一下。

在 config/UrlRewriting.config 中,您可以添加如下简单规则:

<add name="myRule"
          virtualUrl="^~/city/(.*)"
          rewriteUrlParameter="ExcludeFromClientQueryString"
          destinationUrl="~/city?page="
          ignoreCase="true" />

然后它会读取 Umbraco 中的城市页面,并且还会有一个 ?page= 查询字符串。

所以 http://www.example.com/city/A?id=1&type=9 会像 http://www.example.com/city?page=A&id=1&type=9 一样阅读您的页面,但 url 仍然是 http://www.example.com/city/A?id=1&type=9

要创建更漂亮的 url,您可以使用:

<add name="myPrettyRule"
          virtualUrl="^~/city/(.*)/(.*)/(.*)"
          rewriteUrlParameter="ExcludeFromClientQueryString"
          destinationUrl="~/city?page=&id=&type="
          ignoreCase="true" />

您的 url 将如下所示 http://www.example.com/city/A/1/9