因为我不熟悉ASP.NET核心中的Razor Pages概念,所以我想要应用一个通用的URL来将区域性参数传递给路由
我已经使用MVC做到了这一点,但我也想将其应用于Razor pages这里是我在MVC中所做的,它根据需要工作
routes.MapRoute(
name: "default",
template: "{culture}/{controller=Home}/{action=Index}/{id?}");
我已经将它应用于特定的页面,并且它也在工作
options.Conventions.AddPageRoute("/RealEstate/Index", "{culture}/RealEstate");
但是当我想申请所有页面时,它不能工作,我不知道应该将什么作为PageName传递
options.Conventions.AddPageRoute("*", "{culture}/{*url}");
我还想从这个约定中排除管理文件夹为siteName.com/admin而不是en-US/Admin。我还需要在用户第一次打开站点时在URL中设置默认区域性,例如设置为siteName.com并加载默认区域性,甚至默认加载siteName.com/en-US
谢谢。
发布于 2018-06-22 22:54:21
感谢Kirk Larkin的帮助
我使用了他的答案,我添加了一个小的修改,将管理员排除在文化路由之外,并在没有选择文化时为网站设置默认的文化
options.Conventions.AddFolderRouteModelConvention("/", model =>
{
foreach (var selector in model.Selectors)
{
if (selector.AttributeRouteModel.Template.StartsWith("Admin"))
{
selector.AttributeRouteModel = new AttributeRouteModel
{
Order = -1,
Template =
selector.AttributeRouteModel.Template,
};
}
else
{
selector.AttributeRouteModel = new AttributeRouteModel
{
Order = -1,
Template = AttributeRouteModel.CombineTemplates(
"{culture=en-US}",
selector.AttributeRouteModel.Template),
};
}
}
});
https://stackoverflow.com/questions/50698799
复制相似问题