Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > custom resource manager in ASP.NET 2.0

Reply
Thread Tools

custom resource manager in ASP.NET 2.0

 
 
Martin Bischoff
Guest
Posts: n/a
 
      08-31-2005
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
 
Reply With Quote
 
 
 
 
=?Utf-8?B?V2FqYWhhdCBBYmJhcw==?=
Guest
Posts: n/a
 
      08-31-2005
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.

--
Wajahat Abbas
http://www.dotnetpakistan.com
http://www.wajahatabbas.com


"Martin Bischoff" wrote:

> 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
>

 
Reply With Quote
 
 
 
 
Steven Cheng[MSFT]
Guest
Posts: n/a
 
      08-31-2005
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 <(E-Mail Removed)>
| 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: <(E-Mail Removed)>
| Newsgroups: microsoft.public.dotnet.framework.aspnet
| NNTP-Posting-Host: 194.209.202.1
| Lines: 1
| Path: TK2MSFTNGXA01.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFT NGP09.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
|

 
Reply With Quote
 
Brock Allen
Guest
Posts: n/a
 
      09-01-2005
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.A ppSettings[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




 
Reply With Quote
 
Steven Cheng[MSFT]
Guest
Posts: n/a
 
      09-01-2005
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: <(E-Mail Removed)>
| From: Brock Allen <(E-Mail Removed)>
| Subject: Re: custom resource manager in ASP.NET 2.0
| References: <(E-Mail Removed)>
| 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!TK2MSFT NGP11.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.A ppSettings[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
|

|
|

 
Reply With Quote
 
Martin Bischoff
Guest
Posts: n/a
 
      09-01-2005
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 Allen wrote:
> 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.A ppSettings[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

>
>
>
>

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Resource manager problem: naming for embedded resource. Dirc Khan-Evans ASP .Net 1 10-17-2005 12:52 PM
The system cannot locate the resource specified. Error processing resource avishosh XML 2 08-08-2004 06:28 AM



Advertisments