ASP.NET 2.0 Resources

Powered by Blogger

ASP.NET 2.0: Custom Resource Provider Using Sql Database

The world of Web applications is quite different from Windows forms. The solutions that perform great for Windows applications are sometimes quite pain when developing solution designed for the web. ASP.NET 2.0 introduces new feature called declarative localization expressions. It allows you to easily localize web pages and by default it uses .resx files stored in App_LocalResources and App_GlobalResources folders in your web application. Visual studio 2005 supports easy resource creation for each web page by "Generate local resources..." menu entry. Localization to different language/culture is so simple as copying and renaming this automatically generated file and adding desired locale code to it's file name.

But there are also some drawbacks when using this in ASP.NET 2.0 web applications...

  • The resource files (satelite assemblies) are locked all the time, the application is running (it's not easy to update there localized resources).
  • It's difficult (if not impossible) to manage these resources directly from your own web application (for example let the user create new localization or edit existing ones on ther own).

But wait, we are in ASP.NET 2.0. Many thing can be extended and so this Resource provider can be. All you need is simply create your own ResourceProviderFactory based on ResourceProviderFactory class and modify web.config file. Now imagine, you could have your resources stored in Sql (or any other) database.

public sealed class SqlResourceProviderFactory : ResourceProviderFactory
{
    public override IResourceProvider 
        CreateGlobalResourceProvider(string classKey) {
        return new SqlResourceProvider(null, classKey);
    }
    public override IResourceProvider
        CreateLocalResourceProvider(string virtualPath) {
        return new SqlResourceProvider(virtualPath, null);
    }
}

And coresponding declaration in web.config file...

<system.web>
    <globalization 
        resourceProviderFactoryType="Core.Localization.SqlResourceProviderFactory"/>
    ...

This is all you need (except of course writing your own localization resource provider) to swap ASP.NET 2.0 core resource management functionality and suply your own implementation. The ResourceProviderFactory contains two methods...

  • CreateGlobalResourceProvider - used for creating provider for global resources (accessed by GetGlobalResourceObject method or those declaratively used as <%$ Resources:Class, ResourceID %>)
  • CreateLocalResourceProvider - used for local resources (accessed by GetLocalResourceObject method or those declaratively used as meta:resourcekey="Button1")

The IResourceProvider interface that is return by these two methods contains definition for following method and property.

object GetObject(string resourceKey, CultureInfo culture)
IResourceReader ResourceReader

The GetObject method is used to get resource by resourceKey string and specific culture, where ResourceReader property returns all resources for specified virtualPath and current culture. I will not discuss any other details, instead i'm providing links to some custom database ResourceProviders implemented by other users...

31 Comments:

  • I changed the GetResources function of the Helper class to interact with Oracle. When I simply write the query, Select Fields From Tablename, then it works fine. But when I changed this query into parameterized query, it doesn't work even CreateLocalResourceProvider function isn't execute.
    I m also much astonished when I try to apply filter on dataview after getting all records from plan query (not parametrized)into a datable, the same problem occurs, even when I simply apply if statement before adding resouces into the Hashtable, same problem occurs.

    But one thing which may help for some guru to answer me is when I open the Default.aspx page is desig n view, lable control showing error "Object reference not set to instance of an object". but it shows its value perfectly when I execute this site using plan query.

    A lot of thanks in advance.

    By Blogger Unknown, at 1:26 PM  

  • I believe it is ethical to use the custom essay writing services. You do not still anything, you pay enough fair price for the service you use, you simply delegate the part of your work and can concentrate on what really matters to you. You are free to get an outside help from bestcustomessay.org/essays and delegate your writing assignments to professional writers same as if you would get your watches fixed or car repaired by third party experts.

    By Blogger ADmin, at 3:31 PM  

  • thanks for your sharing, I appreciate this. keep up the good work)
    essay writing service

    By Blogger David, at 6:25 PM  

  • The next magnificent document, almost like which he wrote. From either of the the things which I'd like on the net - ended up being typically the this aspect there isn't any disadvantage during measurements, for instance the the only real bed-sheet to a pieces of paper nor roughly a. A "freedom" is not going to sure your notions and also assist you to fit say all of your thought process but additionally just about every that are anxious for getting these products yourself.
    mobile casino

    By Blogger Unknown, at 7:10 PM  

  • You are looking for herbal solutions to miss v? capable of dealing with vaginal discharge, itching in miss v, cure the infection and irritation of the miss v, v miss the freshness treating, curing cysts, to constrict you and miss v to prevent cervical cancer? Crystal X solutions handle, made ??from natural natural ingredients making it safe for use.
    Crystal X
    Crystal X Jogja
    crystal x Nasa
    Ciri-ciri Crystal X Asli
    Cara Mengobati Keputihan

    By Blogger Unknown, at 6:04 AM  

  • see your next time distributor crystal x

    By Blogger Unknown, at 2:42 AM  

  • By Blogger Unknown, at 5:56 AM  

  • What makes me appreciate the blogger so much is the critical analysis on such a wide subject. I have learned a lot of things because the author clearly that he has grasped the subject under study. In addition to that, there are many things which I have learned and more so the new concepts of transportation. I need help to paraphrase my Literature Review

    By Blogger Unknown, at 3:22 PM  

  • By Blogger Unknown, at 5:43 AM  

  • This comment has been removed by the author.

    By Blogger Unknown, at 9:46 AM  

  • This comment has been removed by the author.

    By Blogger Unknown, at 6:06 AM  

  • This comment has been removed by the author.

    By Blogger Unknown, at 3:10 AM  

  • This comment has been removed by the author.

    By Blogger Unknown, at 4:13 AM  

  • Thanks you for sharing bali wedding photographer

    By Blogger Unknown, at 9:45 AM  

  • By Blogger Unknown, at 11:05 AM  

  • This comment has been removed by the author.

    By Blogger Unknown, at 8:48 AM  

  • This comment has been removed by the author.

    By Blogger Unknown, at 9:46 AM  

  • This comment has been removed by the author.

    By Blogger Unknown, at 6:37 AM  

  • By Blogger Unknown, at 8:12 AM  

  • good news and very interesting sablon surabaya murah

    By Blogger chiby loupatty, at 10:09 AM  

  • Good bloog Jual tali rope

    By Blogger Mas Aguz, at 10:07 AM  

  • informasi yang sangat menarik untuk di simak jual cream pemutih wajah alami

    By Blogger chiby loupatty, at 4:48 AM  

  • bila anda ingin mencari tempat Jual mesin bordir komputer bekas murah di Surabaya mungkin kalian dapat berkunjung tempat kami. Kami mempunyai mesin bordir komputer bekas dengan kualitas yang bagus dan kondisi yang baik. Mesin bordir bekas milik kami kami jual juga sudah memakai sistem komputer yang modern dan juga mempunyai kecepatan untuk proses jahit yang cepat. Mesin bordir bekas yang kami tawarkan selain mempunyai kualitas mesin yang bagus tetapi juga memiliki hasil bordir yang bagus juga
    Lokasi Jual mesin bordir komputer bekas di Surabaya milik kami milik kami tidak hnaya mempunyai kualitas yang bagus namun kami juga mempunyai mesin bordir dengan harga yang cukup terjangkau. Kami mempunyai harga mesin bordir yang berbeda-beda yang bisa di sesuaikan dengan keinginan anda. Harga yang kami tawarkan juga dapat anda tanyakan langsung kepada kami.
    Tempat Jual mesin bordir komputer bekas di tempat kami memiliki berbagai merek mesin bordir terkenal dengan kualitas yang baik. Kami mempunyai merek mesin bordir komputer bekas seperti yaitu lung xiang , Fu hao, Feiya, Dahao, Xiong. tak hanya memiliki kualitas baik, Semua jenis mesin bordir tersebut memiliki Harga mesin bordir komputer bekas di Surabaya yang berbeda-beda sesuai seperti keinginan anda.
    lokasi Jual mesin bordir komputer bekas tempat Surabaya di tempat kami mempunyai 2 tipe alat bordir komputer yaitu alat bordir komputer tipe 6 kepala dan juga jenis 12 kepada yang bisa di sesuaikan seperti keinginan anda. Kedua jenis mesin bordir komputer tersebut mempunyai kualitas yang sama baiknya dan juga masih mempunyai kondisi yang bagus. Anda dapat berkunjung langsung kondisi alat bordir second yang kita miliki ke tempat milik kami yang ada di daerah surabaya.

    By Blogger Reza bordir, at 8:05 AM  

  • thanks for sharing this article jasa pasang penangkal petir jakarta

    By Blogger chiby loupatty, at 6:43 AM  

  • this is great article jasa kirim barang ke indonesia

    By Blogger chiby loupatty, at 10:43 AM  

  • terima kasih informasinya sangaat bermanfaat bali trekking tour package

    By Blogger chiby loupatty, at 6:48 AM  

  • Semangat sore

    By Blogger Mas Aguz, at 11:32 AM  

  • https://vidogarment.com/ konveksisurabaya

    By Blogger vido garment, at 9:05 AM  

  • By Blogger vido garment, at 9:07 AM  

  • By Blogger vido garment, at 9:07 AM  

  • By Blogger Travel Umroh, at 9:44 AM  

Post a Comment

<< Home

Created dolly