locked
How to edit values of Resx files at runtime in .Net Core? RRS feed

  • Question

  • User-432327085 posted

    My goal is to implement the changing values of resources 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 files at the runtime, because all their values are stored on the resx files. I have 3 resx files for each different language. In my case I want the translation can be maintain later by an admin at runtime. For example admin can add, edit or delete the entry for the language at runtime.

    Wednesday, February 24, 2021 8:44 AM

All replies

  • User1535942433 posted

    Hi ermii10,

    As far as I think,you could do like this:

    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.

    More details,you could refer to below article:

    https://docs.microsoft.com/en-us/dotnet/framework/resources/working-with-resx-files-programmatically

    https://forums.asp.net/t/1869308.aspx?Update+Resx+file+at+runtime

    Best regards,

    Yijing Sun

    Thursday, February 25, 2021 7:20 AM
  • User-432327085 posted

    Hi yij sun,
    Thanks for answering.

    1). I use folder "Resources" which contains my three resources files and also I am using the latest version of .Net Core.

    2).I am not allowed to use another file type, so all I have to do is using these three .resx files for three different languages. The reason of doing this is all about these .resx files because they contains 2470 names and their relevant values. These resources names are then used generally in my project. The reason why I tend to do these runtime editing resources is that some users maybe do not like our preferences of resources that are created earlier, and so their Administrator can change these named resources in project at Runtime.

    Thursday, February 25, 2021 9:06 AM
  • User1535942433 posted

    Hi ermii10,

    I don't  recommend having to modify it.If it is a mandatory request, use a flat file xml instead and write an application for that. You'll need to modify your app to read in the XML instead.

    Best regards,

    Yijing Sun

    Friday, February 26, 2021 5:25 AM