简体   繁体   中英

Content/Page structure in Umbraco

I am using Umbraco in MVC.

I have create a dynamic page in MVC umbraco that works with querystring parameter

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).

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.

How do I create above pages in Umbraco? How to create above Url? How to share Code in my original "City"" page?

I am new to Umbraco so please advise.

You should read the documentation on Route Hijacking: 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:

<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.

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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