如何动态地加载和转换在Web应用程序(ASP.NET)资源文件而无需重新编译? [英] How to dynamically load and switch the resource file in the web app (ASP.NET) without recompiling?

查看:133
本文介绍了如何动态地加载和转换在Web应用程序(ASP.NET)资源文件而无需重新编译?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想资源文件(包含标签等文本)存储在数据库中我的web应用程序能够编辑和动态后(可能在UI)创建它们。我的想法是存储整个在XML列中的 RESX 文件,然后直接加载需求 - 根据不同的语言和当前用户的各种属性,当他登录到应用程序或切换上下文。最重要的是这些资源不仅取决于用户,但也可以通过用户无需再次登录关闭和切换一些背景信息,文化信息(在本例中名为群,没有什么做与一组用户)。

I would like to store the resource files (containing texts for labels etc.) for my web application in the database to be able to edit and create them dynamically later (probably in the UI). My idea was to store the whole resx file in an xml column and simply load it on demand - depending on the language and some other attributes of the current user when he is logging into the application or switching the context. The important thing is that the resources do not only depend on the culture info of the user but also on some context information that can be switched by user without logging off and on again (in our case called "group", not having anything to do with a group of users).

是否有可能以某种方式从外部源加载资源的内容,并简单地切换它们而不Web应用程序正在由服务器重新编译?我知道有一些关于这一点我可以勾起来,实现自定义资源提供商,直接从数据库中读取接口,但是它是否能够与RESX文件不知何故工作,它很可能会令事情更容易。

Is it possible somehow to load the contents of the resources from an external source and simply switch them without web application being recompiled by the server ? I know that there are some interfaces on which I could hook up and implement a custom resources provider which reads from the database directly but if it could work somehow with the resx files it would probably make things a lot easier..

推荐答案

pretty晚,但因为没有答案呢。

Pretty late but since there is no answer as of yet.

System.Resources.ResourceReader resourceReader 
    = new System.Resources.ResourceReader("PathToResourceFile");

这是pretty多少呢。现在,您可以创建一个像en.resx或de.resx资源文件,并根据用户的语言加载它们。类似

That's pretty much it. Now you can create resource files like en.resx or de.resx and load them depending on the users language. Something like

System.Resources.ResourceReader resourceReader 
    = new System.Resources.ResourceReader(HttpContext.Current.Request.UserLanguages[0] 
    + ".resource");

请记住,以提供与你不支持的语言用户的默认语言(资源文件)。

Keep in mind to provide a default language (resource file) for a user with a language you don't support.

编辑:

看看这个链接

这篇关于如何动态地加载和转换在Web应用程序(ASP.NET)资源文件而无需重新编译?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆