简体   繁体   English

Umbraco 中的内容/页面结构

[英]Content/Page structure in Umbraco

I am using Umbraco in MVC.我在 MVC 中使用 Umbraco。

I have create a dynamic page in MVC umbraco that works with querystring parameter我在 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

Inside Umbraco I have content page named City (along with its DocumentType and template) and in my MVC project the Controller and Action Method names are City and City (action method takes parameter id and type).在 Umbraco 中,我有一个名为 City 的内容页面(以及它的 DocumentType 和模板),在我的 MVC 项目中,Controller 和 Action Method 名称是 City 和 City(操作方法采用参数 id 和 type)。

Now I need to create multiple pages out of it sharing the functionality of page "City" eg现在我需要创建多个页面来共享页面“城市”的功能,例如

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

Each of these pages needs to display same dynamic content depend on Querystring parameter along with some fix content that I want to be managed by CMS.这些页面中的每一个都需要显示相同的动态内容,这取决于 Querystring 参数以及我希望由 CMS 管理的一些修复内容。

How do I create above pages in Umbraco?如何在 Umbraco 中创建上述页面? How to create above Url?如何创建上面的Url? How to share Code in my original "City"" page?如何在我原来的“城市”页面分享代码?

I am new to Umbraco so please advise.我是 Umbraco 的新手,所以请指教。

You should read the documentation on Route Hijacking: https://our.umbraco.org/documentation/reference/routing/custom-controllers您应该阅读有关路由劫持的文档: https : //our.umbraco.org/documentation/reference/routing/custom-controllers

There's also quite a few tutorials and blog posts around the web dealing with this kind of thing, so it's worth doing a search.网络上也有很多教程和博客文章处理这种事情,所以值得搜索一下。

In config/UrlRewriting.config, you could add a simple rule like this:在 config/UrlRewriting.config 中,您可以添加如下简单规则:

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

It will then read the City page in umbraco and will a ?page= querystring as well.然后它将读取 umbraco 中的 City 页面,并且还会读取?page=查询字符串。

So http://www.example.com/city/A?id=1&type=9 will read your page like http://www.example.com/city?page=A&id=1&type=9 but the url will still be http://www.example.com/city/A?id=1&type=9所以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

To create an even prettier url you could use:要创建更漂亮的网址,您可以使用:

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

Your url will then look like this http://www.example.com/city/A/1/9您的网址将如下所示http://www.example.com/city/A/1/9

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

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