Global resource vs. Local resource in ASP.NET(ASP.NET 中的全局资源与本地资源)
问题描述
我们使用 resx 文件来本地化我们的 Web 应用程序.当只有一个页面使用某个短语时,我们通常会创建本地 resx 文件(映射到特定页面),而当多个页面需要该短语时,我们会创建全局 resx 文件.
但是全局 resx 文件的好处是它们是一个类,你可以像调用类的属性一样调用短语:
We use resx files to localize our web applications. We usually create local resx files (that map to a specific page) when only one page uses a certain phrase, and a global resx file when more than one page needs the phrase.
But the good thing about global resx files is that they are a class, and you can call the phrases like you call properties of a class:
Resource.UI.iNotFound
Resource.UI.iNotFound
所以我在想 - 为什么要有本地 resx 文件?为什么不对整个应用程序使用一个全局 resx 文件,这样可以避免调用不存在的短语导致运行时错误?
So I was thinking - why have local resx files at all? why not use one global resx file for the whole application, and that way avoid runtime errors from calling non-existent phrases?
我确定有一个很好的答案,我只是不知道它是什么......
I'm sure there's a good answer for that, I just don't know what it is....
推荐答案
我一直在寻找指南,并在 MSDN:
I kept on looking for guidelines, and found this in MSDN:
在全局和本地资源文件之间进行选择
您可以使用全局的任意组合和 Web 中的本地资源文件应用.通常,您添加资源到全局资源文件当你想分享资源时页面之间.全球资源资源文件也是强类型的当您想要访问文件时以编程方式.
You can use any combination of global and local resource files in the Web application. Generally, you add resources to a global resource file when you want to share the resources between pages. Resources in global resource files are also strongly typed for when you want to access the files programmatically.
但是,全局资源文件可以变大,如果你存储所有其中的本地化资源.全球的资源文件也可以更多难以管理,如果不止一个开发人员正在研究不同的页面但在单个资源文件中.
However, global resource files can become large, if you store all localized resources in them. Global resource files can also be more difficult to manage, if more than one developer is working on different pages but in a single resource file.
本地资源文件更容易管理单个 ASP.NET 的资源网页.但你不能分享页面之间的资源.此外,你可能会创建很多本地的资源文件,如果你有很多页面必须本地化为许多语言.如果网站很大许多文件夹和语言,本地资源可以快速扩展中的组件数应用领域.
Local resource files make it easier to manage resources for a single ASP.NET Web page. But you cannot share resources between pages. Additionally, you might create lots of local resource files, if you have many pages that must be localized into many languages. If sites are large with many folders and languages, local resources can quickly expand the number of assemblies in the application domain.
当您更改默认资源文件时,本地或全局,ASP.NET重新编译资源并重新启动ASP.NET 应用程序.这个可以影响你的整体表现地点.如果添加卫星资源文件,它不会导致重新编译资源,但ASP.NET 应用程序将重新启动.
When you make a change to a default resource file, either local or global, ASP.NET recompiles the resources and restarts the ASP.NET application. This can affect the overall performance of your site. If you add satellite resource files, it does not cause a recompilation of resources, but the ASP.NET application will restart.
所以看来编程团队需要权衡每种方法的优缺点,然后选择对他们有利的方法.
So it seems that it's really up to the programming team to weigh the pros and cons of each method and choose what's good for them.
这篇关于ASP.NET 中的全局资源与本地资源的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:ASP.NET 中的全局资源与本地资源
基础教程推荐
- rabbitmq 的 REST API 2022-01-01
- 将 Office 安装到 Windows 容器 (servercore:ltsc2019) 失败,错误代码为 17002 2022-01-01
- 为什么Flurl.Http DownloadFileAsync/Http客户端GetAsync需要 2022-09-30
- SSE 浮点算术是否可重现? 2022-01-01
- 如何在 IDE 中获取 Xamarin Studio C# 输出? 2022-01-01
- 将 XML 转换为通用列表 2022-01-01
- 有没有办法忽略 2GB 文件上传的 maxRequestLength 限制? 2022-01-01
- c# Math.Sqrt 实现 2022-01-01
- 如何激活MC67中的红灯 2022-01-01
- MS Visual Studio .NET 的替代品 2022-01-01