Can I combine local resources in satellite assemblies?

后端 未结 1 1653
北恋
北恋 2021-01-02 23:04

I have a lot of local resourse files

  • /Controls/App_LocalResources/SomeControl.ascx.resx,
  • /Pages/App_LocalResources/SomePage.aspx.resx, etc.
相关标签:
1条回答
  • 2021-01-02 23:54

    Your question isn't really too clear on whether you are looking for a feature of VS2008 or a feature of the ASP.NET framework. So I'll go with the code solution.

    The implicit binding syntax you're using uses ASP.NET's default LocalResourceProvider which takes in the path of page under which the resources live to work out which resources to load. If your resources are stored elsewhere and you still want to use the implicit binding systax in your code in front you'll need to use your own Provider. Sounds complicated but it's fairly straightforward.

    To do this you'll need to first subclass ResourceProviderFactory

    and override both

    IResourceProvider CreateGlobalResourceProvider(string classKey)
    IResourceProvider CreateLocalResourceProvider(string virtualPath)
    

    ...then implement your own IResourceProvider that gets your resources from your satellite assemblies using a ResourceManager

    public interface IResourceProvider
    {
         object GetObject(string resourceKey, CultureInfo culture);
         IResourceReader ResourceReader { get; }
    }
    

    You then need to add configuration to your web.config file to let ASP.NET know to use your SatelliteResourceProviderFactory and move your resources in to your external assemby, but that should be you good to go.

    Plenty of documentation can be found here...under the "Building a Database Resource Provider" section...

    http://msdn.microsoft.com/en-us/library/aa905797.aspx#exaspnet20rpm_topic4

    0 讨论(0)
提交回复
热议问题