【问题标题】:ASP.NET MVC RouteConfig - Changes Detecting LateASP.NET MVC RouteConfig - 延迟检测更改
【发布时间】:2020-03-31 12:52:20
【问题描述】:

我正在使用动态路由配置:

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 }
    );
}

但是这些网址长期无效。 (例如:localhost/123/Product_Name 在几小时后激活)

提前感谢您的帮助

【问题讨论】:

  • 你在哪里打电话?如果它处于启动状态,则您的应用程序可能会在空闲后停止运行。然后在下一个请求时它启动并运行这个逻辑。为什么你首先需要这些动态路线?构建您的路线,这样您就不必动态添加新路线。
  • 我使用这种方法是因为网站上有多种语言支持,并且每种语言都有单独的 url 支持。新产品时如何触发 routeconfig?

标签: c# asp.net asp.net-mvc model-view-controller routeconfig


【解决方案1】:

是的,你可以只拥有一个路由器

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

应该这样做。

【讨论】:

  • 我使用自定义 url,例如德语的“Produkte”,英语的“Product”等。所以我使用多个
  • 嗯,听起来你想将“Produkte”和“Product”都映射到同一个动作。我认为这真的很难,我会​​阅读一些关于特定语言 c# 的文章,例如 codeproject.com/Articles/1095786/…
猜你喜欢
  • 2011-12-29
  • 2012-11-21
  • 1970-01-01
  • 2018-03-17
  • 1970-01-01
  • 1970-01-01
  • 2012-12-31
  • 1970-01-01
  • 2018-04-13
相关资源
最近更新 更多