Base solution for your next web application

Activities of "ESTeam"

Hi,

the problem (the last one reported in Azure Front Door) is resolved, the solution is here (#6 Overwrite ‘Host’ server variable on Windows IIS Web Apps, with applicationHost.xdt and Web.config): https://www.patrickob.com/2022/04/06/azure-front-door-afd-app-gateway-app-service-unexpected-issues/

Therefore, we no longer need to modify the request header.

thank you, Dirceu

Hi,

We already change to Azure Front Door and now we can change the language but when we call the method https://plano-mais-cuf-api-dev.sistemasaude.pt/AbpUserConfiguration/GetAll?d=1709222850822 is not returning the tenant id so regardless of the address it is always redirecting to the host: Host = https://host-dev.sistemasaude.pt Tenant 1 (default) - https://default-dev.sistemasaude.pt Tenant 2 (plano-mais-cuf) - https://plano-mais-cuf-dev.sistemasaude.pt

in the development environment (with azure front door):

in the UAT environment (with Gateway) - https://plano-mais-cuf-api-uat.sistemasaude.pt/AbpUserConfiguration/GetAll?d=1709223616322:

Do you have any tips on what could be causing this as this problem did not occur when using the Gateway? Both environments are equal in terms of code deployed and databases are also equal.

best regards, Dirceu

Hi,

Thanks. Is it possible to access your solution somehow ? It would be nice for us to test this using your project.

The source code? i've been testing localy We are currently changing the Azure environment to use Azure Front Door instead of Application Gateway. After testing (If the tests run successfully), it may no longer be necessary to modify the name of the request header ".AspNetCore.Culture" - We can wait and see if it works.

Hi @ESTeam

Just to be sure, you only have this problem for the not loggedin users, is that correct ?

Hi,

I've tested again now and after the login it only works if i open a new private window in the browser (Edge) - In chrome never works (even if you open a new incognito window). Before login never works.

Hi,

In that case, you can change the cookie name in language-switch.component.ts

Hi,

I tried one of 2 things and neither of them worked on the login page (after doing the login both solutions worked):

  1. I changed the name of the cookie on the server side from “.AspNetCore.Culture” to “AspNetCoreCulture”, as you indicated. On the client side, I set the cookie in language-switch.component.ts component (and also changed the name in file AppPreBootstrap.ts):
  2. I changed the name of the cookie on the server side from “.AspNetCore.Culture” to “AbpLocalizationCultureName” (this is another cookie used by ASP.NET Zero that was previously modified (because of the "." in the cookie name that had to be removed) from Abp.Localization.CultureName to AbpLocalizationCultureName). On the client side, I changed the name in file AppPreBootstrap.ts

I also tried changing the cookie whenever I send the language in the request header but it didn't work on the login page either:

The 2 cookies are with the "en" culture but the site remains in "pt-PT":

The request header is also in "en":

best regards, Dirceu

Hi,

Sorry for the delay. It seems like there was a few more place to change the default culture name. You can follow steps below to do this.

  1. Create a custom RequestCultureProvider as shown below;
public class MyCookieRequestCultureProvider: CookieRequestCultureProvider 
{ 
    public override async Task<ProviderCultureResult> DetermineProviderCultureResult(HttpContext httpContext) 
    { 
        CookieName = "AspNetCoreCulture"; 
        return await base.DetermineProviderCultureResult(httpContext); 
    } 
} 
  1. Then, use it like this in your Startup.cs file;
app.UseAbpRequestLocalization(opts => 
{ 
  opts.RequestCultureProviders.Insert(0, new MyCookieRequestCultureProvider()); 
}); 

These two steps allow you to read the cookie with name AspNetCoreCulture. You also need to change the name when the cookie is written. Follow steps below to do this.

  1. Create the Controller below in your Web.Mvc project;
public class MyAbpLocalizationController : AbpController 
{ 
    protected Abp.Web.Http.IUrlHelper UrlHelper; 
    private readonly ISettingStore _settingStore; 
 
    private readonly ITypedCache<string, Dictionary<string, SettingInfo>> _userSettingCache; 
 
    public MyAbpLocalizationController( 
        Abp.Web.Http.IUrlHelper urlHelper, 
        ISettingStore settingStore, 
        ICacheManager cacheManager) 
    { 
        UrlHelper = urlHelper; 
        _settingStore = settingStore; 
        _userSettingCache = cacheManager.GetUserSettingsCache(); 
    } 
 
    [DisableAuditing] 
    public virtual ActionResult ChangeCulture(string cultureName, string returnUrl = "") 
    { 
        var cookieValue = CookieRequestCultureProvider.MakeCookieValue(new RequestCulture(cultureName, cultureName)); 
 
        Response.Cookies.Append( 
            "AspNetCoreCulture", 
            cookieValue, 
            new CookieOptions 
            { 
                Expires = Clock.Now.AddYears(2), 
                HttpOnly = true 
            } 
        ); 
 
        if (AbpSession.UserId.HasValue) 
        { 
            ChangeCultureForUser(cultureName); 
        } 
 
        if (Request.IsAjaxRequest()) 
        { 
            return Json(new AjaxResponse()); 
        } 
 
        if (!string.IsNullOrWhiteSpace(returnUrl)) 
        { 
            var escapedReturnUrl = Uri.EscapeDataString(returnUrl); 
            var localPath = UrlHelper.LocalPathAndQuery(escapedReturnUrl, Request.Host.Host, Request.Host.Port); 
            if (!string.IsNullOrWhiteSpace(localPath)) 
            { 
                var unescapedLocalPath = Uri.UnescapeDataString(localPath); 
                if (Url.IsLocalUrl(unescapedLocalPath)) 
                { 
                    return LocalRedirect(unescapedLocalPath); 
                } 
            } 
        } 
 
        return LocalRedirect("/"); 
    } 
 
    protected virtual void ChangeCultureForUser(string cultureName) 
    { 
        var languageSetting = _settingStore.GetSettingOrNull( 
            AbpSession.TenantId, 
            AbpSession.GetUserId(), 
            LocalizationSettingNames.DefaultLanguage 
        ); 
 
        if (languageSetting == null) 
        { 
            _settingStore.Create(new SettingInfo( 
                AbpSession.TenantId, 
                AbpSession.UserId, 
                LocalizationSettingNames.DefaultLanguage, 
                cultureName 
            )); 
        } 
        else 
        { 
            _settingStore.Update(new SettingInfo( 
                AbpSession.TenantId, 
                AbpSession.UserId, 
                LocalizationSettingNames.DefaultLanguage, 
                cultureName 
            )); 
        } 
 
        _userSettingCache.Remove(AbpSession.ToUserIdentifier().ToString()); 
    } 
} 
  1. And change the places in your MVC project where @Url.Action("ChangeCulture", "AbpLocalization") is called. You need to use @Url.Action("ChangeCulture", "MyAbpLocalization"...

Hi,

in the client side we use Angular 9 (not .NET MVC), so we don't have any reference to ChangeCulture (both on the client and server side):

best regards, Dirceu

Hi again,

Sorry to insist, but do you have an expected date for presenting a solution (to change the request header from ".AspNetCore.Culture" to "AspNetCoreCulture")?

best regards, Dirceu

Hi @ESTeam

Thanks, we will try this and get back to you soon.

Hi,

Do you have any news? - we are unable to complete the migration due to this problem/limitation in Azure/Gateway/NGINX - the solution would be to remove the dots from the name of the request header (but the solution you suggested did not work). Note: We are using Angular 9 and .NET Core 3.1 - ASP.NET ZERO version 8.7.0

best regards, Dirceu

Question

Using ASP.NET CORE & Angular v11.4.1 Theme 13.

I have a problem with the menu, which is different from Administration. For example, in Administration if i click click on "Users", the Administration menu doesn't collapse (it is supposed to). However in others, it collapses.

For example, If i click here:

The menu looks like this, collapsed:

Hi,

Did you also change it on the server side ? If not, you can try this https://stackoverflow.com/a/49268627

Hi,

I made this change on the server and client side and it didn't work, after the change I can't change the language in the local environment.

Showing 1 to 10 of 53 entries