This description that stands after the address is called Slug. In this case, what you need to do is a specific route handler. For example:
Appstart Routeconfig.Cs
routes.MapRoute(
"Default",
"{controller}/{action}/{id}",
new { controller = "Default", action = "Index", id = UrlParameter.Optional }
).RouteHandler = new MeuManipuladorDeRota();
Infrastructure Meumanipuladorderota.Cs
public class MeuManipuladorDeRota : MvcRouteHandler
{
protected override IHttpHandler GetHttpHandler(RequestContext requestContext)
{
var url = requestContext.HttpContext.Request.Path.TrimStart('/');
if (!string.IsNullOrEmpty(url))
{
ItemDePagina item = GerenciadorDeRedirecionamento.ObterPaginaPorUrl(url);
if (item != null)
{
MontarRequisicao(item.Controller,
item.Action ?? "Index",
item.ConteudoId .ToString(),
requestContext);
}
}
return base.GetHttpHandler(requestContext);
}
private static void MontarRequisicao(string controller, string action, string id, RequestContext requestContext)
{
if (requestContext == null)
{
throw new ArgumentNullException("requestContext");
}
requestContext.RouteData.Values["controller"] = controller;
requestContext.RouteData.Values["action"] = action;
requestContext.RouteData.Values["id"] = id;
}
}
Viewmodels Itemdepagina.Cs
public class ItemDePagina {
public String Controller { get; set; }
public String Action { get; set; }
public int ConteudoId { get; set; }
}
Managed Infrastructure redirection.Cs
public static class GerenciadorDeRedirecionamento
{
public static ItemDePagina ObterPaginaPorUrl(string url)
{
ItemDePagina item = null;
/* Aqui você pesquisa na entidade pela descrição, passando o parâmetro url. */
/* Este é o ponto mais importante da lógica, que é onde você vai pesquisar o item de acordo com as suas regras de negócio. */
/* Depois você monta um objeto ItemDePagina (no caso, item) e o devolve. */
return item;
}
}
Do you know how the site works? Please indicate when to find an answer that solves your problem by marking it as a solution (by clicking on the "right" icon just below the answer score)
– Tiago César Oliveira