The resource manager may not retrieve culture-specific resources when you use the Thread.CurrentUICulture property in ASP.NET (903902)



The information in this article applies to:

  • Microsoft .NET Framework 1.1

SUMMARY

SYMPTOMS

When you use the Thread.CurrentUICulture property in Microsoft ASP.NET, the resource manager may not retrieve culture-specific resources as expected. For example, the resource manager may only retrieve the default resources.

Additionally, you may receive an error message that is similar to the following if you rename the default resources to be culture-specific:
Could not find any resources appropriate for the specified culture (or the neutral culture) in the given assembly.

CAUSE

This issue occurs when the following conditions are true:
  • You use impersonation in the ASP.NET application.
  • The impersonated account does not have the correct permissions on the Temporary ASP.NET Files folder.

RESOLUTION

To resolve this issue, use one of the following methods.

Method 1: Use the ReverttoSelf function in the application code

To use the Thread.CurrentUICulture property, use the ReverttoSelf function in the application code. For example, use code that is similar to the following in ASP.NET:
using System.Runtime.InteropServices;
using System.Threading;
using System.Globalization;
using System.Resources;
using System.Reflection;
using System.Security.Principal;
using System.Security;

public class WebForm1 : System.Web.UI.Page
{
            private bool Success;
		WindowsIdentity impersonated;

            [DllImport("advapi32")]
		public  static  extern bool RevertToSelf();
private void Page_Load(object sender, System.EventArgs e)
		{
			//Preserve impersonated identity.
			impersonated = WindowsIdentity.GetCurrent();
			//Revert to process identity.
			Success  = RevertToSelf();
			if (Success)
			{
				CultureInfo ci =new CultureInfo("<Culture>");
				Assembly a = Assembly.Load("<SatelliteAssemblyName>");
				Thread.CurrentThread.CurrentUICulture = ci;
				ResourceManager rm = new ResourceManager("<RootNameOfTheResources>",a);
				Label1.Text = rm.GetString("<ResourceName>");
				//Re-establish impersonation.
				impersonated.Impersonate();
			}
				
		}
}
Notes
  • <Culture> represents the culture that you want to use.
  • <SatelliteAssemblyName> represents the satellite assembly that contains the resources that are appropriate for the specified culture.
  • <RootNameOfTheResources> represents the base name for the resource file.
  • <ResourceName> represents the name of the resource that you want to obtain.

Method 2: Configure the permissions on the temporary ASP.NET folder

Give the impersonated identity Write and Modify permissions on the Temporary ASP.NET Files folder.

WORKAROUND

To work around this issue, turn off impersonation in the application.

MORE INFORMATION

If impersonation is used in the application, the culture-specific resource DLL files are shadow copied to the Temporary ASP.NET Files folder by using the impersonation token when the files are loaded. If the impersonated identity does not have the correct permissions on the Temporary ASP.NET Files folder, the shadow copy operation fails.

If impersonation is not used in the application, the process identity is used, and the shadow copy operation works as expected.

Modification Type:MajorLast Reviewed:8/31/2005
Keywords:kbtshoot kbprb KB903902 kbAudDeveloper