Good URLs based on multiple parameters

it’s clear what are the benefits of using good URLs in your website.

Let me clarify what I ask using an example. To note that the objects here cannot be identified uniquely by name.

Say that the user wants to see all the radio stations registered on your site that are available in a specific place. This is done by accessing the URL: http://example.com/radios/1234/radio-paris-eiffel-tower

  • 1234 - in this case, it is a unique location identifier
  • radio-paris-eiffel-tower is additional information to make the URL more enjoyable.

If users want to see all the places where a radio station is available, they can use: http://example.com/locations/abcd/radio-xyz

  • abcd - the radio is identified here

Now the question is: what is a good URL for accessing the radio stations of a particular radio station in a specific place (e.g. name, frequency, ...)?

http://example.com/radio/1234/radio-paris-eiffel-tower/abcd/radio-xyz or http://example.com/radio/details?radioid=1234&locationid=abcd/radio-xyz-at- paris-eiffel-tower

Do you have any suggestions and could you also give me an example of how to encode a route for your proposed URL?

Many thanks.

ps : actually thinking of the addresses above instead of http://example.com/radios/1234/radio-paris-eiffel-tower

http://example.com/1234/radio-paris-eiffel-tower/radios/

wdyt?

RadiosController.ListByLocation(int locationId)?

+3
1

. Global.asax.cs:

public static void RegisterRoutes(RouteCollection routes)
{
    routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

    routes.MapRoute(
        "Radio and Frequency Route", // Route name
        "radio/details/{radioId}/{locationId}/{someUnusedName}", // URL with parameters
        new
        {
            controller = "Some",
            action = "SomeAction",
            radioId = string.Empty,
            locationId = string.Empty
        }
    );

    routes.MapRoute(
        "Default", // Route name
        "{controller}/{action}/{id}", // URL with parameters
        new { controller = "Home", action = "Index", id = UrlParameter.Optional } // Parameter defaults
    );

}

:

public class SomeController : Controller
{
    public ActionResult SomeAction(string radioId, string locationId)
    {
        ViewData["radioId"] = radioId;
        ViewData["locationId"] = locationId;

        return View();
    }

}

URL-, /radio/details:

http://localhost:51149/radio/details/123/456/moo
http://localhost:51149/radio/details/abc/xyz/foo

URL-, . , /radio/details - ?

+2

Source: https://habr.com/ru/post/1753492/


All Articles