gpt4 book ai didi

asp.net - ASP.NET 中的全局资源与本地资源

转载 作者:行者123 更新时间:2023-12-03 07:38:13 29 4
gpt4 key购买 nike

我们使用 resx 文件来本地化我们的 Web 应用程序。当只有一个页面使用某个短语时,我们通常创建本地 resx 文件(映射到特定页面),当多个页面需要该短语时,我们通常创建全局 resx 文件。
但全局 resx 文件的好处是它们是一个类,您可以像调用类的属性一样调用这些短语:

资源.UI.iNotFound

所以我在想 - 为什么要有本地 resx 文件?为什么不对整个应用程序使用一个全局 resx 文件,这样可以避免调用不存在的短语而导致运行时错误?

我确信有一个很好的答案,但我只是不知道它是什么......

最佳答案

我一直在寻找指南,并在 MSDN 中找到了它:

Choosing Between Global and Local Resource Files

You can use any combination of globaland local resource files in the Webapplication. Generally, you addresources to a global resource filewhen you want to share the resourcesbetween pages. Resources in globalresource files are also strongly typedfor when you want to access the filesprogrammatically.

However, global resource files canbecome large, if you store alllocalized resources in them. Globalresource files can also be moredifficult to manage, if more than onedeveloper is working on differentpages but in a single resource file.

Local resource files make it easier tomanage resources for a single ASP.NETWeb page. But you cannot shareresources between pages. Additionally,you might create lots of localresource files, if you have many pagesthat must be localized into manylanguages. If sites are large withmany folders and languages, localresources can quickly expand thenumber of assemblies in theapplication domain.

When you make a change to a default resource file,either local or global, ASP.NETrecompiles the resources and restartsthe ASP.NET application. This canaffect the overall performance of yoursite. If you add satellite resourcefiles, it does not cause arecompilation of resources, but theASP.NET application will restart.

因此,看来编程团队确实需要权衡每种方法的优缺点,并选择对他们有利的方法。

关于asp.net - ASP.NET 中的全局资源与本地资源,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/446321/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com