问题描述
我正在寻找一种扩展应用程序以使用特定于客户端的资源文件的方法.目前,我有针对不同文化的资源文件,效果很好.但是现在我想为每个客户端使用不同的资源文件,如果我没有特定于客户端的文件,则应该加载默认的文件.
I am looking for a way to extend my application to use a client specific resource file. Currently I have resource files for different cultures which is working fine. But now I want to have different resource file for each client and if I don't have client specific file then it should load the default one.
这是我目前正在做的事情
This is what I am doing currently:
App_GlobalResources GR.resx GR.ru-RU.resx
App_GlobalResources GR.resx GR.ru-RU.resx
我读到这样的资源
text ='<%$ Resources:GR,home%>'
text='<%$ Resources:GR,home %>'
或
GetGlobalResourceObject("GR","home")
GetGlobalResourceObject("GR","home")
这就是我想要的:App_GlobalResourcesGR.resxGR.ru-RU.resx
This is what I want:App_GlobalResourcesGR.resxGR.ru-RU.resx
Client1 GR.resx GR.ru-RU.resx
Client1 GR.resx GR.ru-RU.resx
Client2 GR.resx GR.ru-RU.resx
Client2 GR.resx GR.ru-RU.resx
我不想像阅读资源那样更改页面上的代码,可以吗?
I do not want to change the code on my pages the way I am reading resources, is it possible?
推荐答案
好吧,在评论中讨论之后,我真正理解您的问题.我将使用以下解决方案.根据您的示例获利:
Ok Safeer, after discussion in comments I truly understand your problem. I would use following solution. Basing on your example with profits:
-
为利润准备一些不同的条目(取决于客户类型或其他):
Prepare few different entries for Profit (depend on customer type or whatever):
- key1:"Type1Profit"值:"Available Profit"
- key2:"Type2Profit"值:"Total Profit"
其中TypeN是您的客户类型.
Where TypeN is your customer type.
然后在视图中执行以下操作:
After that in view do something like this:
text='<%$ Resources:GR, string.Format("{0}Profit", customer.Type) %>'
或
GetGlobalResourceObject("GR",string.Format("{0}Profit", customer.Type))
借助此解决方案,您应该获得所需的密钥,当然还有对客户而言特定的价值.
Thanks to this solution you should get key which you want and of course specific value for customer.
这篇关于asp.net中特定于客户的资源文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!