custom resource manager in ASP.NET 2.0

M

Martin Bischoff

Hi,

is it possible to implement custom resource managers for ASP.NET 2.0 so
that strings can be read from a database (for example)?

Ideally, it should be possible to configure the custom resource manager
in web.config, so that it replaces the default resource manager. Using
the <%$ ... %> syntax should read the strings via the custom resource
manager, e.g. when used like this:


<asp:Label ID="Label1" runat="server"
Text="<%$ Resources:Resource, STRING_ID %>"></asp:Label>


Thanks for any help,
Martin
 
G

Guest

Martin,

I have done this in one of my project. I created an extended resource
manager which gets the strings file from the xml rather getting it from the
compiled resource, so it is possible, that you can extend the asp.net
resource manager according to your requirement.
 
S

Steven Cheng[MSFT]

Hi Martin,

Welcome to ASP.NET newsgroup.
Regarding on the asp.net 2.0 resource manager question you mentioned,
based on my understanding, this is not available in the comming 2.0 versino
of the ASP.NET. Since the <%$ %> expression are translated to the actual
code/statements at compile time, this translation is fixed in the compiler,
we won't be able to customize it with our own type. Currently I think we
may consider use the <%# %> databinding experssion with out own custom
class or function to retrieve the resource as we like.

Thanks,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
--------------------
| Date: Wed, 31 Aug 2005 09:19:53 +0200
| From: Martin Bischoff <[email protected]>
| User-Agent: Mozilla Thunderbird 1.0 (Windows/20041206)
| X-Accept-Language: en-us, en
| MIME-Version: 1.0
| Subject: custom resource manager in ASP.NET 2.0
| Content-Type: text/plain; charset=ISO-8859-1; format=flowed
| Content-Transfer-Encoding: 7bit
| Message-ID: <[email protected]>
| Newsgroups: microsoft.public.dotnet.framework.aspnet
| NNTP-Posting-Host: 194.209.202.1
| Lines: 1
| Path: TK2MSFTNGXA01.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP09.phx.gbl
| Xref: TK2MSFTNGXA01.phx.gbl
microsoft.public.dotnet.framework.aspnet:121351
| X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet
|
| Hi,
|
| is it possible to implement custom resource managers for ASP.NET 2.0 so
| that strings can be read from a database (for example)?
|
| Ideally, it should be possible to configure the custom resource manager
| in web.config, so that it replaces the default resource manager. Using
| the <%$ ... %> syntax should read the strings via the custom resource
| manager, e.g. when used like this:
|
|
| <asp:Label ID="Label1" runat="server"
| Text="<%$ Resources:Resource, STRING_ID %>"></asp:Label>
|
|
| Thanks for any help,
| Martin
|
 
B

Brock Allen

Yes, these can be customized. They're called expression builders. I posted
in the past month an example, but here's another:

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

public class AppSettExBld : ExpressionBuilder
{
public static string GetVal(string param)
{
return System.Web.Configuration.WebConfigurationManager.AppSettings[param];
}
public override System.CodeDom.CodeExpression GetCodeExpression(BoundPropertyEntry
entry, object parsedData, ExpressionBuilderContext context)
{
CodeMethodInvokeExpression ex = new CodeMethodInvokeExpression(new CodeTypeReferenceExpression(typeof(AppSettExBld)),
"GetVal", new CodePrimitiveExpression(entry.Expression.ToString().Trim()));
return ex;
}
}


The method you should customize is GetVal. This sample simply reads from
<appSettings> but you could read from a database. To configure you need to
modify the <compilation> section in web.config:

<compilation debug="true" defaultLanguage="C#">
<expressionBuilders>
<add expressionPrefix="AppSet" type="AppSettExBld, __code"/>
</expressionBuilders>
</compilation>


And now you can use <%$ AppSett:SomeKeyToTheGetValMethod %> in your ASPX
pages.
 
S

Steven Cheng[MSFT]

Thanks a lot for both Wajahat and Brock's informative suggestions.

Seems I've really missed such a great feature. I'll keep this in mind and
have some further investigate in the
asp.ne whidbey.

Thanks again for your contribution.

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
--------------------
| Message-ID: <[email protected]>
| From: Brock Allen <[email protected]>
| Subject: Re: custom resource manager in ASP.NET 2.0
| References: <[email protected]>
| Mime-Version: 1.0
| Content-Transfer-Encoding: 8bit
| Content-Type: text/plain; charset=iso-8859-1; format=flowed
| X-Newsreader: JetBrains Omea Reader 469.1
| Newsgroups: microsoft.public.dotnet.framework.aspnet
| Date: Wed, 31 Aug 2005 21:19:41 -0700
| NNTP-Posting-Host: 12.162.27.25
| Lines: 1
| Path: TK2MSFTNGXA01.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP11.phx.gbl
| Xref: TK2MSFTNGXA01.phx.gbl
microsoft.public.dotnet.framework.aspnet:121612
| X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet
|
| Yes, these can be customized. They're called expression builders. I
posted
| in the past month an example, but here's another:
|
| using System.Web.Compilation;
| using System.CodeDom;
|
| public class AppSettExBld : ExpressionBuilder
| {
| public static string GetVal(string param)
| {
| return
System.Web.Configuration.WebConfigurationManager.AppSettings[param];
| }
| public override System.CodeDom.CodeExpression
GetCodeExpression(BoundPropertyEntry
| entry, object parsedData, ExpressionBuilderContext context)
| {
| CodeMethodInvokeExpression ex = new CodeMethodInvokeExpression(new
CodeTypeReferenceExpression(typeof(AppSettExBld)),
| "GetVal", new
CodePrimitiveExpression(entry.Expression.ToString().Trim()));
| return ex;
| }
| }
|
|
| The method you should customize is GetVal. This sample simply reads from
| <appSettings> but you could read from a database. To configure you need
to
| modify the <compilation> section in web.config:
|
| <compilation debug="true" defaultLanguage="C#">
| <expressionBuilders>
| <add expressionPrefix="AppSet" type="AppSettExBld, __code"/>
| </expressionBuilders>
| </compilation>
|
|
| And now you can use <%$ AppSett:SomeKeyToTheGetValMethod %> in your ASPX
| pages.
|
| -Brock
| DevelopMentor
| http://staff.develop.com/ballen
|
|
|
| > Hi,
| >
| > is it possible to implement custom resource managers for ASP.NET 2.0
| > so that strings can be read from a database (for example)?
| >
| > Ideally, it should be possible to configure the custom resource
| > manager in web.config, so that it replaces the default resource
| > manager. Using the <%$ ... %> syntax should read the strings via the
| > custom resource manager, e.g. when used like this:
| >
| > <asp:Label ID="Label1" runat="server"
| > Text="<%$ Resources:Resource, STRING_ID %>"></asp:Label>
| > Thanks for any help,
| > Martin
|

|
|
 
M

Martin Bischoff

Thanks to everyone. In the meantime I have also found out about expression
builders, and these allow me to do what I want.

I have also read about ResourceProviderFactory, IResourceProvider and
IResourceReader. But I did not find a way to configure ASP.NET to use my
custom resource manager instead of the default one (at least for strings).

Regards,
Martin

Brock said:
Yes, these can be customized. They're called expression builders. I
posted in the past month an example, but here's another:

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

public class AppSettExBld : ExpressionBuilder
{
public static string GetVal(string param)
{
return
System.Web.Configuration.WebConfigurationManager.AppSettings[param];
}
public override System.CodeDom.CodeExpression
GetCodeExpression(BoundPropertyEntry entry, object parsedData,
ExpressionBuilderContext context)
{
CodeMethodInvokeExpression ex = new
CodeMethodInvokeExpression(new
CodeTypeReferenceExpression(typeof(AppSettExBld)), "GetVal", new
CodePrimitiveExpression(entry.Expression.ToString().Trim()));
return ex;
}
}


The method you should customize is GetVal. This sample simply reads from
<appSettings> but you could read from a database. To configure you need
to modify the <compilation> section in web.config:

<compilation debug="true" defaultLanguage="C#">
<expressionBuilders>
<add expressionPrefix="AppSet" type="AppSettExBld,
__code"/>
</expressionBuilders>
</compilation>


And now you can use <%$ AppSett:SomeKeyToTheGetValMethod %> in your ASPX
pages.




Hi,

is it possible to implement custom resource managers for ASP.NET 2.0
so that strings can be read from a database (for example)?

Ideally, it should be possible to configure the custom resource
manager in web.config, so that it replaces the default resource
manager. Using the <%$ ... %> syntax should read the strings via the
custom resource manager, e.g. when used like this:

<asp:Label ID="Label1" runat="server"
Text="<%$ Resources:Resource, STRING_ID %>"></asp:Label>
Thanks for any help,
Martin
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,009
Latest member
GidgetGamb

Latest Threads

Top