从另一个项目访问RESX资源文件 [英] Access resx resource files from another project

查看:124
本文介绍了从另一个项目访问RESX资源文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我在这里这么温柔的第一个问题!

this is my first question on here so be gentle!

即时通讯使用asp.net 3.5,我的解决方案目前有2个项目,一个API类项目和一个网站项目,该项目类中我有一个名为checkin.resx的资源文件。对我来说,能够从我的网站项目中访问的资源文件,我不得不将访问修饰符公众,这允许我使用一个强类型的名称存取权限的资源,例如: CkiApi .Checkin.Resources.Checkin.OCKI_HeaderText ,其中签是.resx文件和OCKI_HeaderText是资源的关键。

Im using asp.net 3.5, my solution currently has 2 projects, an API class project and a website project, within the class project i have a resource file named checkin.resx. For me to be able to access the resource files from my website project, i had to set the "Access Modifier" to public, this allowed me to use a strongly typed name to acces the resources for example: CkiApi.Checkin.Resources.Checkin.OCKI_HeaderText, where Checkin is the .resx file and OCKI_HeaderText is the resource key.

问题IM面对的是,即时通讯无法从前端的aspx code访问的资源,例如,settign标签或验证错误消息的文本属性。我曾尝试下面的语法无济于事:

The problem im facing is that im unable to access the resources from front end aspx code, for example, settign a text property of a label or a validation error message. I have tried the following syntax to no avail:

<asp:Label AssociatedControlID="IdentMethods" EnableViewState="false" ID="lblIdentMethod" runat="server" Text="<%$ Resources: CkiApi.Checkin.Resources.Checkin, OCKI_IdentificationMethod %>"></asp:Label>

我得到的错误是与关键'OCKI_IdentificationMethod未找到资源对象。但不管是什么我的类名设置为,我得到了同样的错误,即时通讯思想的,因为它试图在网站项目看,但我不能弄清楚如何告诉它看API!任何人都可以帮忙吗?!

the error i get is "The resource object with key 'OCKI_IdentificationMethod' was not found." but regardless of what i set the class name to, i get the same error, im thinking its because its trying to look in the website project but i cant figure out how to tell it to look at the API! Can anyone help?!

我能够使用以下设置非服务器端标签:

i am able to set non server side tags using the following:

<div id="OckiIntroText">
           <%=CkiApi.Checkin.Resources.Checkin.OCKI_IntroText%>
</div>

非常感谢!

推荐答案

资源EX pressions(&LT;%$资源:的ClassKey,获取ResourceKey%GT; )使用<一个href=\"http://msdn.microsoft.com/en-us/library/system.web.compilation.resourceex$p$pssionbuilder.aspx\">ResourceEx$p$pssionBuilder幕后类。这个类可以查找全局和局部的资源,只在(网站 App_GlobalResources文件 App_LocalResources文件文件夹)。

Resource expressions (<%$ Resources: ClassKey, ResourceKey %>) use ResourceExpressionBuilder class behind the scene. This class can lookup global and local resources only (in website's App_GlobalResources and App_LocalResources folders).

相反,你可以使用<一个href=\"http://weblogs.asp.net/infinitiesloop/archive/2006/08/09/The-$c$cEx$p$pssionBuilder.aspx\">$c$cEx$p$pssionBuilder类从不同的项目访问资源。以下是如何使用它。

Instead, you can use CodeExpressionBuilder class to access resources from different project. Here's how to use it.

codeEX pressionBuilder类添加到APP_ $ C $文件夹C:

Add CodeExpressionBuilder class to App_Code folder:

using System.CodeDom;
using System.Web.Compilation;
using System.Web.UI;

[ExpressionPrefix("Code")]
public class CodeExpressionBuilder : ExpressionBuilder
{
   public override CodeExpression GetCodeExpression(BoundPropertyEntry entry,
      object parsedData, ExpressionBuilderContext context)
   {
      return new CodeSnippetExpression(entry.Expression);
   }
}

添加以下的System.Web /编译部分在web.config中:

Add the following to system.web/compilation section in web.config:

<compilation debug="false">
   ...
   <expressionBuilders>
      <add expressionPrefix="Code" type="CodeExpressionBuilder"/>
   </expressionBuilders>
</compilation>

最后,你可以打电话到您的.resx文件生成的强类型的类:

Finally, you can call into strongly-typed class generated for your .resx file:

<asp:Label ID="Label1" runat="server" Text="<%$ Code: ClassLibrary1.Resource1.String1 %>" />

这篇关于从另一个项目访问RESX资源文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆