繁体   English   中英

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(操作方法采用参数 id 和 type)。

现在我需要创建多个页面来共享页面“城市”的功能,例如

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? 如何在我原来的“城市”页面分享代码?

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

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

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

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

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

然后它将读取 umbraco 中的 City 页面,并且还会读取?page=查询字符串。

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

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

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

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM