如何从ASP.NET页面访问Resource.resx?

Roc*_*ark 6 asp.net

我想从ASP.NET页面访问资源文件.我有一个名为"Resources"的文件夹,其中包含与页面处于同一级别的文件"WebResources.resx".生成的WebResources.Designer.cs中的公共类的名称也是"WebResources"我的页面名称是"formulargenerator.aspx".从代码隐藏的访问工作完美.我可以通过两种方式访问​​:

ResourceManager rm = new ResourceManager(typeof(WebResources));
string val = rm.GetString("Key");
Run Code Online (Sandbox Code Playgroud)

string val = WebResources.Key;
Run Code Online (Sandbox Code Playgroud)

但是,如果我不想重命名资源文件,如何直接从页面访问?我曾尝试使用App_LocalResources文件夹 - 无法访问.只有资源文件的名称与页面相同才有效.如何访问资源的语法?下面的代码不起作用.必须/我可以导入命名空间吗?

<asp:Label Text="<%$Resources: WebResources, Key%>" runat="server" />
Run Code Online (Sandbox Code Playgroud)

亲切的问候提前

Iva*_*vov 1

您可能想查看ASP.NET 网页资源概述。本地资源特定于具体的 aspx 页面,并使用与全局应用程序资源不同的命名约定。如果使用全局资源,您正在使用的资源标签更有可能起作用。