开发者

ASP.NET routes problem

开发者 https://www.devze.com 2023-02-26 16:06 出处:网络
If i go to mysite/Catalog it breaks. How can solve it? routes.MapRoute( \"Localization\", // Route name

If i go to mysite/Catalog it breaks. How can solve it?

routes.MapRoute(
    "Localization", // Route name
    "{lang}/{controller}开发者_开发知识库/{action}/{id}", // URL with parameters
    new { controller = "Home", action = "Index", id = UrlParameter.Optional } // Parameter defaults
);

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

routes.MapRoute(
    "Root",
    "",
    new { controller = "Home", action = "Index", id = "" }
);


It will match your first route thinking "Catalog" is "lang". You need to create constraint for your localizations.

Following route should match requests prefixed with any language code (like en, cs, de or en-US, en-GB...) correctly

routes.MapRoute("Localization", "{lang}/{controller}/{action}/{id}",
    new { controller = "Home", action = "Index", id = UrlParameter.Optional },
    new { lang = "[a-z]{2}(-[a-z]{2})" }
);
0

精彩评论

暂无评论...
验证码 换一张
取 消