This is a .NET 4.5 project, it has been set up long time before my time here, so not a lot of details as to why it's been done this way.
We have a web application where each language has its own resx file. On every page load, the values are loaded from the resx file, the usual way.
string strLangResourceValue = (string)HttpContext.GetGlobalResourceObject(lang, strLangResourceKey);
This works fine. Might be worth mentioning that this line of code is in a separate project so it can be shared with multiple other projects we have under the solution.
In the views (Razor) we do @Application.GetLangResource("Some_Key");
to retrieve the value we need. The language is taken from the session model stored in HttpContext.
The issue raises when we change the language, every partial view on that page is translated accordingly except for that 'user settings' page we changed the language on. What makes it strange is that we have two views, one read only page to only display the data and one which contains the actual form to modify the values and neither one of them is translated.
The known issues are:
- I can't now set CultureInfo within the web application, I need to use the session model to get this information and use the above line of code to grab the data.
- Force refreshing the browser, clearing cookies and cache does not fix the issue.
- Only restarting the IIS server fixes the issue (the resx file is recompiled)
I know that the resx file are compiled during runtime and are static. They are not changed in the code during application run, it's only the user session that changes. The above list has been attempted to get to the bottom of the issue, but restarting the application every time someone changes their language is not an option (as you might of guessed).
Is there an obvious solution to this that I'm missing? There is no resx error, it's IIS cache (or at least it seems like it is) on just the two specific pages. They are built the same way as all the other ones, just not switching the language. This applies to all users when they change their languages.
I have tried to manually clear the cache using the below lines of code, that did not do the job issue still persisted.
Resources.AppSettings.ResourceManager.ReleaseAllResources();
Resources.English.ResourceManager.ReleaseAllResources();
Resources.Dutch.ResourceManager.ReleaseAllResources();
HttpResponse.RemoveOutputCacheItem("/Views/User/userViewDetails.cshtml");
foreach(System.Collections.DictionaryEntry entry in HttpContext.Cache) {
HttpContext.Cache.Remove((string) entry.Key);
}