ASP.NET Local Resource Infrastructure Capabilities
I have an ASP.NET 5 application and I am currently implementing localization.
The resources are in the ASP.NET folder App_LocalResources
and everything is working correctly. At least while it is still under development. I have the following ResourceCultureFilterAttribute
:
using MyProject.App_LocalResources;
public class ResourceCultureFilterAttribute : ActionFilterAttribute
{
public override void OnActionExecuting(ActionExecutingContext filterContext)
{
string language = GetClientLanguageFromCookiesDoesntMatter();
var culture = new CultureInfo(language);
GlobalResources.Culture = culture;
}
}
And now I access it this way in the Razor view:
@GlobalResources.SomeResourceName
Now I'm worried about the Culture
property of the autogenerated resource class static
.
Does this mean that this property is set for a thread or for each application pool (please specify the correct one), but not for each user >?
If so, multiple users are just overriding and using the same value and will certainly cause localization issues.
I know how to fix this by replacing direct access:
@GlobalResources.ResourceManager.GetString("ResourceName",
new CultureInfo(GetClientLanguageFromCookiesDoesntMatter());
But maybe there is a better solution - something important that I just don't see or don't know. Perhaps there is a special type property CurrentUserCulture
, a custom multi-user resource class, an attribute, or something else to provide simple and straightforward localization in an ASP.NET project.
source to share
No one has answered this question yet
Check out similar questions: