I have developed a .net6 mvc application with globalization, I’ve created the role folder structure for Views/Controller/ViewModels resx for each language. While debuging running on IIS Express from Visual Studio or accessing it via localhost in the IIS Server the localization is working fine. But when I try to acces it from outside by the hostname it doesn’t change the language, I’ve made a lot of search, added parameters to the web.config, but it didn’t work. Could someone give a hand?
This is the program.cs from the application
using FastReport.Data;
using Microsoft.AspNetCore.Localization;
using Microsoft.AspNetCore.Mvc.Razor;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Localization;
using MYAPP;
using MYAPP.Models;
var builder = WebApplication.CreateBuilder(args);
// Add services to the container.
builder.Services.AddLocalization(options => options.ResourcesPath = "Resources");
builder.Services.AddRazorPages().AddViewLocalization(LanguageViewLocationExpanderFormat.Suffix).AddDataAnnotationsLocalization();
builder.Configuration
.SetBasePath(Directory.GetCurrentDirectory()).AddJsonFile("appsettings.json");
builder.Services.AddDbContext<SncMesSloRpcContext>(options =>
options.UseSqlServer(builder.Configuration.GetConnectionString("DatabaseContext")));
builder.Services.AddTransient(typeof(IStringLocalizer<>), typeof(StringLocalizer<>));
var app = builder.Build();
var supportedCultures = new[] { "en", "pt", "es" };
var localizationOptions = new RequestLocalizationOptions()
.AddSupportedCultures(supportedCultures)
.AddSupportedUICultures(supportedCultures)
.SetDefaultCulture("es");
localizationOptions.RequestCultureProviders = new List<IRequestCultureProvider>()
{
new QueryStringRequestCultureProvider(),
new CookieRequestCultureProvider(),
new AcceptLanguageHeaderRequestCultureProvider()
};
app.UseRequestLocalization(localizationOptions);
// Configure the HTTP request pipeline.
if (!app.Environment.IsDevelopment())
{
app.UseExceptionHandler("/Home/Error");
// The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
app.UseHsts();
}
app.UseHttpsRedirection();
app.UseStaticFiles();
app.UseRouting();
app.UseAuthorization();
app.MapControllerRoute(
name: "default",
pattern: "{controller=Login}/{action=Index}");
//pattern: "{controller=Dashboards}/{action=Index}");
app.Run();