A
A
Andrey Mokeev2017-02-19 22:43:00
ASP.NET
Andrey Mokeev, 2017-02-19 22:43:00

ASP .NET Core: Routing. How to make multiple categories at the beginning of a URL?

So, there is a task:
It is necessary to skip requests for the url
site.com/events/2017/06/wwdc.html
, or in a more general form

site.com/category1/subcategory1/subcategory2/...../subcategoryN/page-title.html

as another example: on a c action
site.com/cars/tesla/model-s/is-it-worth-it.html
controller or something like that... At compile time, the number of these subcategories is not known, that is, one article can have 1 category and that's it, and the other thing 3-4, or even 5 But what is unambiguously known is that all such pages end with , where pageTitle is some page title, probably unique. I did not find a way to implement this with the built-in ASP.Net Core routing tools, and the documentation does not explain too much how you can override the behavior. So, is it possible to do this, and if so, how? ArticlesControllerIndex(string title)
/pageTitle.html

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Andrey Mokeev, 2017-02-19
@mokeev1995

If you put something like this at the end of the file, then everything should work, but you have to manually parse everything.

app.UseMvc(routes =>
        {
            routes.MapRoute(
                name: "category-article",
                template: "{*article}",
                defaults: new
                {
                    controller = "Home",
                    action = "ReadCategoryAndPage"
                });
        });

You can read more details here

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question