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.
- 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); } }
- 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.
- 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()); } }
- 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
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.
Hi @ESTeam
I'm glad that the DB error is fixed. When I look at the Microsoft's answer, it seems like you must change the request header names. You can change the
Abp.TenantId
used in AspNet Zero as shown below;
- For client side, set
abp.multiTenancy.tenantIdCookieName
.- For server side, set
Configuration.MultiTenancy.TenantIdResolveKey
For Cookies generated by ASP.NET Core, you can check its documentation.
If you can share how did you change
AspNetCoreCulture
, we can investigate why it didn't work.
Hi,
I changed the Abp.TenantId header as indicated and it worked, but when I change the ".AspNetCore.Culture" header to "AspNetCoreCulture" I can no longer modify the language in my local environment. I just modified the method getRequetHeadersWithDefaultValues on the client side: ![Capture.JPG] Note: I had previously removed the dots from all cookie names.
best regards, Dirceu
Hi,
Cannot insert the value NULL into column 'Id', table 'UatCufHealthPlan.dbo.AbpUserTokens'; column does not allow nulls.
This last error seems unrelated to using "." in cookies and request headers. The Id field must be auto-increment so it must be set by the database provider. Are there any changes on the database as well ?
For the issue using "." in cookies and request headers, I remember this problem from using NGINX. NGINX allows this by a custom configuration. Are you using NGINX ?
I have an response from microsoft - is there anything we can change in the code? (Previously I modified the ".AspNetCore.Culture" header to "AspNetCoreCulture" but I had to revert because I was unable to modify the language in the local environment, in the Azure environment it never worked).
*AppGw V2 uses NGINX. As I previously mentioned we state in our docs that dots are not supported in the request header. A work around is to play with the re-write rule until you get the desired outcome or have the app in the backend support the header without the dots.
Also, periods in header names seem to be in contradiction with RFC7230 https://learn.microsoft.com/en-us/azure/application-gateway/application-gateway-faq#why-are-some-header-values-not-present-when-requests-are-forwarded-to-my-application
RFC: RFC 7230 - Hypertext Transfer Protocol (HTTP/1.1): Message Syntax and Routing (ietf.org)
Please let me know if you need any further assistance.*
Hi,
Regarding the cookies microsoft are checking if any exception can be made on AppGw accepted characters.
I have now verified that the database error occurs because when the tables were migrated, the primary keys were left without the identity.
Thanks, Dirceu
@Simonlum Do you resolve? I have same issue
I have the same challenge as @KPCS. Were you able to resolve it?