«
»

Algemeen

Resource Unloading in a custom ASP.NET Localization Resource Provider

08.12.10 | Comment?

In ASP.NET 2.0 ResourceProviders allow extension of the native resource mechanism with your own resource backing store by implementing a custom ResourceProvider. I’ve recently published an extensive articlethat talks about this process in detail and why this can be quite useful.

One of the issues that I’ve been struggling with is that the ASP.NETResourceProvider(s) are not directly accessible from your ASP.NET code. ASP.NET basically gives you access to HttpContext.GetGlobalResourceObject() and HttpContext.GetLocalResourceObject() but that’s about as close as you can get to the loaded providers ( ASP.NET actually loads many instances of providers – one for each resource set).

Since I built a provider that allows live resource editing as part of the application, and so it’s only logical that you would want to see the changes in the resource provider either immediately or after explicitly refreshing the resources. As it turns out this is not easy to do because ASP.NET hides the Providers from you. No unloading for you!

In the past I’ve used a hack http://west-wind.com/WebLog/posts/5688.aspxto accomplish this: Basically force the AppDomain to unload by either calling HttpRuntime.UnloadAppDomain() or even more hacky by touching web.config causing the timestamp to change and thus forcing ASP.NET to reload the application. Both of these actually work, although both have security issues you need to worry about. The former requires full trust, the latter that you have write file access rights to Web.config neither of which is guaranteed to be available.

*A better way: Hang on to your Hats – er, Providers*

So as I was wrapping up my article I got to thinking about this problem again. With a custom provider implementation it’s actually possible to keep track of the providers as they are loaded. Once you have a list of the providers, unloading the resources is really not difficult – since resources are typically cached in Hashtables/Dictionaries in memory it’s easy to clear them out by releasing each of the dictionaries holding the resource data.

So here’s what I did in my provider (which otherwise is fairly standard implementation so this should be easy to apply to any custom implementation).

I set up a static LoadedProviders property (List<>) that keeps track of all the loaded provider instances, and a method called UnloadProviders() to loop through the list and then call a custom interface method that unloads the providers.

volledig artikel http://www.west-wind.com/weblog/posts/121171.aspx


have your say

Add your comment below, or trackback from your own site. Subscribe to these comments.

Be nice. Keep it clean. Stay on topic. No spam.

You can use these tags:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

:

:


«
»

My Index

0-10

A

Adwords campagne beheer

B

Baare.com
Baare TV
bakgerei voor kindjes

C

CE HTML
Community Server
Chicken coop builder
Chicken coops

D

E

F

Familie Anrijs
FrontierVille
FrontierVille guides review site

G

GarageTV
garagetv.be
Google Adwords - adverteren op zoekmachines
Google-approved Qualified Professional

H

Huur vakantiehuisjes

I

Internet reclame

J

JWI Consulting
JWI Blogt

K

Kabel televisie abonnementen
Kasteel van de Leeuwenridders
KMO website snelheidstest

L

M

N

O

P

P&O ferries
parket en laminaat leggen
Philips Net TV
Playmobilkasteel
Portfolio Development (.NET C# PHP)
Portfolio SEO (Search Engine Optimalisatie)
Provinciaal Voetbal
provinciaal voetbal Antwerpen
provinciaal voetbal Branbant
provinciaal voetbal Limburg
provinciaal voetbal Oost-Vlaanderen
provinciaal voetbal West-Vlaanderen

Q

R

S

SEO analyse
SEO (Search Engine Optimization)
Snelheids voor kmo websites

T

www.telekoop.be (te koop, nieuw & tweedehands)
Top vakanties
tv gids
advies bij tv kopen

U

V

Verjaardagsfeestjes voor kindjes
Voetbal uitslagen
online voetbalschoenen kopen

W

google webmaster tools

X

Y

Z

Zoekmachine optimalisatie