Search code examples
asp.netasp.net-corerazor-pages

How to make the country name to be a part of the URL in Asp.net core Razor pages


We developed a website using ASP.net core Razor Pages so we have some pages in the website served through URLs like

Domain/Solutions
Domain/solutions/details/1
Domain/aboutus

and other many links of course

After completing the development the customer requested to allow the user to select the company branch before browsing the website so the home page of the site will contain multiple cards one for each branch, for Example, "Dubai Branch, USA Branch, ...." If the user clicked Dubai Branch for example we need all the URLs to contain that branch as a parameter like following

Domain/dubai/solutions
Domain/dubai/solutions/details/1
Domain/dubai/aboutus

We need to catch "dubai" as a parameter with all the subsequent requests to filter the content of the pages accordingly and to do this change at a minimal cost, first is that applicable? how to achieve that without many changes


Solution

  • You can mark part of a URL as a param like that

    Domain/{branch}/solutions
    Domain/{branch}/solutions/details/1
    Domain/{branch}/aboutus
    

    so you will be able to read it in your razor page behind code and customer will be able to sent there anything.