Microsoft KB Archive/903902

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

Article ID: 903902

Article Last Modified on 8/31/2005

-

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(&quot;advapi32&quot;)] 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(&quot;&quot;); Assembly a = Assembly.Load(&quot;&quot;); Thread.CurrentThread.CurrentUICulture = ci; ResourceManager rm = new ResourceManager(&quot;&quot;,a); Label1.Text = rm.GetString(&quot;&quot;); //Re-establish impersonation. impersonated.Impersonate; }       } } Notes
 * represents the culture that you want to use.
 * represents the satellite assembly that contains the resources that are appropriate for the specified culture.
 * represents the base name for the resource file.
 * 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.

Keywords: kbtshoot kbprb KB903902

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.