0

我的 CultureTemplateRouteModel 约定:

   public void Apply(PageRouteModel model)
    {
        List<SelectorModel> selectorModels = new List<SelectorModel>();
        foreach (var selector in model.Selectors.ToList())
        {

            var template = selector.AttributeRouteModel.Template;
            selectorModels.Add(new SelectorModel()
            {
                AttributeRouteModel = new AttributeRouteModel
                {
       
                    Template ="/"+ "{culture?}" + "/" + template
                }
            });
        }
        foreach (var m in selectorModels)
        {
            model.Selectors.Add(m);
        }
    }

我的启动配置:

services.AddRazorPages().AddRazorPagesOptions(opts =>
            {
                opts.Conventions.Add(new CultureTemplateRouteModelConvention()); 
               
             
            });
            services.Configure<RequestLocalizationOptions>(options =>
            {
                var supportedCultures = new[]{
        new CultureInfo("en-US"),
        new CultureInfo("de-DE"),

    };
                options.SupportedCultures = supportedCultures;
                options.SupportedUICultures = supportedCultures;
                options.RequestCultureProviders.Insert(0, new RouteDataRequestCultureProvider());
            });

          
    
            services.AddMvc()
            .AddViewLocalization(LanguageViewLocationExpanderFormat.Suffix, options => options.ResourcesPath = "Resources")
                 .AddDataAnnotationsLocalization(
                options =>
                 {
                     options.DataAnnotationLocalizerProvider = (type, factory) =>
                     {
                         var assemblyName = new AssemblyName(typeof(IdentityResource).GetTypeInfo().Assembly.FullName);
                         return factory.Create("IdentityResource", assemblyName.Name);
                     };
                 }
                 );

我还定义了区域,我的本地化在主索引页面上运行良好:

https://localhost:44366/de-DE/Index

但是对于区域中的页面,我将文化作为查询字符串:

https://localhost:44366/Documents?culture=de-DE

而不是我想要的:

https://localhost:44366/de-DE/Documents

我究竟做错了什么?

4

0 回答 0