【发布时间】:2010-07-07 10:50:02
【问题描述】:
如何在 ASP.NET Web 应用程序项目中使用它们?有什么区别吗?
非常感谢
【问题讨论】:
标签: asp.net localization web-application-project app-globalresources
如何在 ASP.NET Web 应用程序项目中使用它们?有什么区别吗?
非常感谢
【问题讨论】:
标签: asp.net localization web-application-project app-globalresources
本地资源:
例如:Default.aspx.resx- 基础资源文件。这是默认或备用资源文件。
Default.aspx.de.resx- 德语等资源文件
全球资源:
Global Resources Localization Suggestion for ASP.NET
全局资源必须存储在应用程序根目录的 App_GlobalResources 中。
// Get the global resource string.
try
{
globalresourcestring = (String)GetGlobalResourceObject("MyResource", "GlobalResourceString1");
}
catch
{
globalresourcestring = "Could not find global resource.";
}
【讨论】:
Resources.GeneralMessages.msg 其中msg 是该资源的名称。
这些是 ASP.NET MVC 5 Web 应用程序的步骤
例如。
<add namespace="ProjectName.App_LocalResources" />
为了在您的 html 代码中访问本地资源文件,您必须 添加
@using ProjectName.App_LocalResources
到页面顶部。
然后您可以访问 App_LocalResources 中的不同资源 通过使用
@NameOfResxFile.NameOfValueInResxFile
我希望这会有所帮助。
【讨论】:
如果您非常确定您的资源存在于您的 .resx 文件中,您可以尝试:
string myValue = HttpContext.GetGlobalResourceObject("MyResourceFile","MyResource").ToString();
如果您不确定您的资源是否存在,您可以使用:
var resultMessage = HttpContext.GetGlobalResourceObject("MyResourceFile","MyResource");
string myValue = resultMessage == null ? string.Empty : resultMessage.ToString();
【讨论】: