Microsoft Knowledge Base Article
This article contents is Microsoft Copyrighted material.
©2005-©2007 Microsoft Corporation. All rights reserved.
Terms
of Use |
Trademarks
Article ID: 903902 - Last Review: August 31, 2005 - Revision: 1.1
The resource manager may not retrieve culture-specific resources when you use the Thread.CurrentUICulture property in ASP.NET
On This Page
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.
APPLIES TO
- Microsoft .NET Framework 1.1
Community Feedback System
Very often, it takes hours to solve a problem. Very often, you've looked high
and low, and have tried a lot of solutions. When you finally found it, chances
are, it was because someone else helped you. Here's your chance to give back.
Use our community feedback tool to let others know what worked for you and what
didn't.
Please also understand that the community feedback system is not warranted to be
correct, it's simply a system that we've built to let people try and help each
other. If something in a feedback response doesn't make sense to you, or you're
not comfortable making changes that the feedback talks about (like registry
edits), please consult a professional.
Thank you for using kbAlertz.com Feedback System.
-- Scott Cate
Be the first to leave feedback, to help others about this knowledge base
article.
(Optional) Name
(Optional)
Public URL Or Email
Comments
No
HTML -- Text Only Please