你好,我有一个名为X.Common.DLL的程序集。它包含了一些用于多语言应用的资源文件,比如Language.resx,Language.en-US.resx等等。
我有一个Web应用程序,其中包含了上述dll作为引用...
那么我该如何在Web应用程序的标记侧使用这些资源文件呢?
Text="<%$ Resources:Class, ResourceKey %>"
是无效的,因为“Class”名称在另一个程序集中...
你好,我有一个名为X.Common.DLL的程序集。它包含了一些用于多语言应用的资源文件,比如Language.resx,Language.en-US.resx等等。
我有一个Web应用程序,其中包含了上述dll作为引用...
那么我该如何在Web应用程序的标记侧使用这些资源文件呢?
Text="<%$ Resources:Class, ResourceKey %>"
是无效的,因为“Class”名称在另一个程序集中...
public class ResourceWrapper
{
private ResourceManager resourceManager;
public ResourceWrapper()
{
resourceManager = new ResourceManager("Namespace.Common", Assembly.Load("x.common"))
}
public string String(string resourceKey)
{
return ResourceManager.GetString(resourceKey);
}
}
有时候找到new ResourceManager(...)的第一个参数的正确名称可能会有些棘手。为了让自己更容易,你可以这样调用:
Assembly.Load("x.common").GetManifestResourceNames() and check the returned results.
<%= Resource.String("MyResourceKey") %>
在web.config中引用其他程序集,以便在Web表单中公开其内容。 http://msdn.microsoft.com/en-us/library/ms164642.aspx
编辑:由于评论下的原因,以下是更详细的答案: 您应该像这样完成webconfig的页面/命名空间部分:
<pages>
<namespaces>
...
<add namespace="My.Fully.Qualified.Namespace"/>
</namespaces>
</pages>