Search code examples
asp.netasp.net-routing

Best practice for making links that take advantage of clean urls


I'm using ASP.NET 4 and the routing engine. In my Global.asax I have something like this.

routes.MapPageRoute(
            "Items",
            "manager/items",
            "~/Manager/Item/Items.aspx"
        );

Is writing a link this this acceptable?:

<a href="/Manager/Items"></a>

Should I be using the <% %> tags and code within to retrieve the route name, "Items" in this case?


Solution

  • Using a method like Page.GetRouteUrl() will most likely be the better option than outputing a <a/> tag directly since changes to the virtual path will be handled by GetRouteUrl

    <a href="<%:Page.GetRouteUrl("Items", null)%>"></a>