0

I am using dynamic routeconfig:

foreach (var urn in db.Urunler.Where(x => x.UrunKategori.DilId == item.Id).ToList())
{
    routes.MapRoute(
       name: "Urun" + urn.Id,
       url: @urn.Id + "/" + @urn.UrnUrl,
       defaults: new { controller = "Urunler", action = "Detay", id = @urn.Id }
    );
}

But these urls are not valid for a long time. (Example: localhost/123/Product_Name activates after a few hours)

Thank you in advance for your help

dcg
  • 4,187
  • 1
  • 18
  • 32
  • 1
    Where are you calling this from? If it's on Startup, your application is likely spinning down after it goes idle. Then on the next request it starts up and runs this logic. By why do you need these routes dynamic in the first place? Build your route so that you don't have to dynamically add new ones. – mason Mar 31 '20 at 12:56
  • I use this method since there are several language support on the site and separate url support for each language. How do I get routeconfig to be triggered when new product? – Türk Yazılımcı Mar 31 '20 at 13:01

1 Answers1

0

Yeah you can just have one router

routes.MapRoute(
               name: "MyUrlRouter",
               url: "{id}/{url}",
               defaults: new { controller = "Urunler", action = "Detay", id = UrlParameter.Optional }
           );

Should do.

Richard Housham
  • 1,525
  • 2
  • 15
  • 31
  • I use custom urls such as "Produkte" for German, "Product" for English etc. So I use more than one – Türk Yazılımcı Mar 31 '20 at 13:18
  • mmm, do sounds like you want to map both 'Produkte' and 'Product' to the same action. I think that's going to be really hard and I would read up on some of articles concerning language specific c# e.g https://www.codeproject.com/Articles/1095786/Route-friendly-localization-of-ASP-NET-MVC – Richard Housham Mar 31 '20 at 13:27