I need to create a setting configuration in my project so user can be able to update the language from my application (not directly from resx file). But the problem is, when i try to create a routine to update resx file at runtime, after that modification
the application rescycled and the session is gone.
Is it possible to update resx file at runtime without restart the session/application?
The resx is compiled into an assembly and an update to assemblies in ~/bin trigger an app domain recycle. So, in short, you don't want to do it this way.
Can you explain in more detail what you're trying to do?
thanks for the answer. My goal is to implement multilingual web application and give the admin the ability to maintain the language through the portal. In order to do that, I need to be able to change resx file at the runtime, because all the language stored
on the resx file. Or do you have maybe another idea in order to accomplish my goal?
So you want the translation to be performed at runtime by an admin type person? Or you already have all the translations done and you just want to show the different languages?
So in that case, I'd say that the .resx approach isn't the right approach. Keep your translated values in a database and render them dynamically. Then the admin can change them via your admin tool.
There are a number of ways this can be accomplished and yes you can even update resx files at runtime, although that's probably not such a good idea.
1) Update Resx Files in App_GlobalResources, App_LocalResources
If you use localization based on 'classic' localization using these folders for resources, it's possible to dynamically update these resx files dynamically at runtime. As others have mentioned these folders are monitored by ASP.NET and if there's a change
the application is recylced which can be expensive in terms of performance, but it works.
The real problem here is that if you make many changes there's a big performance impact on the site, but also if there's any sort of input error or XML encoding error in the .resx files ASP.NET will fail compilation and totally lock up your site.
2) Use a custom ASP.NET Resource Provider
ASP.NET supports creation of custom resource providers that can serve resources from alternate sources. Personally I think that if you need to modify resources dynamically at runtime a database is a better way to do this as it allows you to share the data
among developers. It's also easier to update the localization data without forcing a restart of the app for every single change made.
Some years ago I posted an article on how to create a database driven resource provider along with a sample and online editor.
wapt49
Member
4 Points
16 Posts
Update Resx file at runtime
Dec 28, 2012 09:26 PM|LINK
Hi all,
I need to create a setting configuration in my project so user can be able to update the language from my application (not directly from resx file). But the problem is, when i try to create a routine to update resx file at runtime, after that modification the application rescycled and the session is gone.
Is it possible to update resx file at runtime without restart the session/application?
Many thanks :)
BrockAllen
All-Star
27526 Points
4903 Posts
MVP
Re: Update Resx file at runtime
Dec 28, 2012 09:41 PM|LINK
The resx is compiled into an assembly and an update to assemblies in ~/bin trigger an app domain recycle. So, in short, you don't want to do it this way.
Can you explain in more detail what you're trying to do?
DevelopMentor | http://www.develop.com
thinktecture | http://www.thinktecture.com/
wapt49
Member
4 Points
16 Posts
Re: Update Resx file at runtime
Dec 29, 2012 08:23 AM|LINK
Hi,
thanks for the answer. My goal is to implement multilingual web application and give the admin the ability to maintain the language through the portal. In order to do that, I need to be able to change resx file at the runtime, because all the language stored on the resx file. Or do you have maybe another idea in order to accomplish my goal?
Thanks
BrockAllen
All-Star
27526 Points
4903 Posts
MVP
Re: Update Resx file at runtime
Dec 29, 2012 01:38 PM|LINK
So you want the translation to be performed at runtime by an admin type person? Or you already have all the translations done and you just want to show the different languages?
DevelopMentor | http://www.develop.com
thinktecture | http://www.thinktecture.com/
wapt49
Member
4 Points
16 Posts
Re: Update Resx file at runtime
Dec 29, 2012 02:22 PM|LINK
BrockAllen
All-Star
27526 Points
4903 Posts
MVP
Re: Update Resx file at runtime
Dec 29, 2012 02:24 PM|LINK
So in that case, I'd say that the .resx approach isn't the right approach. Keep your translated values in a database and render them dynamically. Then the admin can change them via your admin tool.
DevelopMentor | http://www.develop.com
thinktecture | http://www.thinktecture.com/
wapt49
Member
4 Points
16 Posts
Re: Update Resx file at runtime
Dec 29, 2012 09:54 PM|LINK
Is there any example to create multilanguage website using database?
Because I still don't have idea to render the translated value into webform. Thanks
BrockAllen
All-Star
27526 Points
4903 Posts
MVP
Re: Update Resx file at runtime
Dec 29, 2012 11:36 PM|LINK
I don't know of any, but you'd basically need to query the DB for each page request for all the translatable strings that need to be displayed.
DevelopMentor | http://www.develop.com
thinktecture | http://www.thinktecture.com/
rstrahl
Contributor
2233 Points
375 Posts
ASPInsiders
MVP
Re: Update Resx file at runtime
Jan 07, 2013 11:41 PM|LINK
There are a number of ways this can be accomplished and yes you can even update resx files at runtime, although that's probably not such a good idea.
1) Update Resx Files in App_GlobalResources, App_LocalResources
If you use localization based on 'classic' localization using these folders for resources, it's possible to dynamically update these resx files dynamically at runtime. As others have mentioned these folders are monitored by ASP.NET and if there's a change the application is recylced which can be expensive in terms of performance, but it works.
The real problem here is that if you make many changes there's a big performance impact on the site, but also if there's any sort of input error or XML encoding error in the .resx files ASP.NET will fail compilation and totally lock up your site.
2) Use a custom ASP.NET Resource Provider
ASP.NET supports creation of custom resource providers that can serve resources from alternate sources. Personally I think that if you need to modify resources dynamically at runtime a database is a better way to do this as it allows you to share the data among developers. It's also easier to update the localization data without forcing a restart of the app for every single change made.
Some years ago I posted an article on how to create a database driven resource provider along with a sample and online editor.
The article can be found here:
http://www.west-wind.com/presentations/wwdbresourceprovider/
A sample can be found here:
http://west-wind.com/WestwindWebToolkit/Westwind.GlobalizationWeb/CustomerList.aspx
(click on the little icons to jump to the resource edit form)
Hope this helps,
+++ Rick ---
West Wind Technologies
Making waves on the Web
www.west-wind.com/weblog