2
votes

I'm working on a project right now which has aspx files in the root folder and one folder named "UserControls" that contains all the ascx files. I had to localize it so I used the App_GlobalResources and App_LocalResources for the Resource files. However, I had a problem with the user controls because they're not reading their respective resource files. I started to make some tests and I realized that they only read the resource files if they're placed on an App_LocalResources subfolder inside their respective containing folder and not in the root folder. As I have too many subdirectories with user controls I wouldn't like to place each local resource file on its main containing folder. It just doesn't make sense. Anyone with some ideas? Thanks in advance.

2

2 Answers

3
votes

Without looking at your project files, I would guess that the pages that aren't reading their resources from the root App_LocalResources folder are the ones whose filename collides with another page. E.g. if you have /cart/Default.aspx and also /myaccount/Default.aspx, then ASP.NET won't know which one matches /App_LocalResources/Default.aspx.resx. That's why it requires those pages' resource files to be in their own subfolders: to make it obvious which page they match.

I think if you want to avoid this you have three options:

  1. Change everything to Global resources. This is not so bad as long as you make sure the resource names are well organized and it's obvious which page they apply to.
  2. Change the page filenames to be unique. This is pretty ugly as it might break redirects in the app, as well as SEO.
  3. Don't use ASP.NET resources for localization, roll your own solution. Seriously, Resources are one of the many nice, seemingly-useful features in ASP.NET (see also Themes, Mobile support, Roles) that in my experience don't scale well to larger projects, and are best ignored in favor of custom solutions. For example, what happens if your ASP.NET app calls a middle-tier DLL that needs to return localized text? Much better in that case to have your own lower-level resource localization system.
0
votes

Check that App_LocalResources directory is located in the same folder of the usercontrol.