Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6821549
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T21:33:29+00:00 2026-05-26T21:33:29+00:00

We have an ASP.NET application that queues some of its long-running operations (generating reports,

  • 0

We have an ASP.NET application that queues some of its long-running operations (generating reports, for example) into the ThreadPool using System.Threading.ThreadPool.QueueUserWorkItem.

We have two problems with this approach:

  1. We run the ASP.Net application pool using a specific domain service account so that it can access remote resources, including files and databases. When the execution starts in the ThreadPool, the user identity of the thread is set to Network Service, which doesn’t allow us to access the remote resources.

  2. The web application can be accessed by users in different countries simultaneously and the format of the data that we provide to each user is based on their culture settings (using the standard globalization settings in web.config). When the queued thread is started, it has also lost this information and reverts to the default culture for the operating system.

Now, we can probably get around most of these issues by capturing the current user identity and culture in a state object and passing that to the background worker, then impersonate the user and set the culture on the thread, but this seems like a very "unclean" way to resolve this issue.

Is there a better way?

Additional information:

Here are the globalization settings from web.config:

<globalization requestEncoding="utf-8" responseEncoding="utf-8" culture="auto" enableClientBasedCulture="true" uiCulture="auto"></globalization>

When a request is processed, ASP.NET automatically sets the Culture and UICulture of the current thread to the user’s requested culture (which is passed automatically by the browser in the Accept-Language header).

This behavior can be replicated by adding the following code to just about any event in the code behind (i.e. button click, page load, etc):

' Called from just about anywhere
ThreadInitiator()

Private Sub ThreadInitator()
   ' Observe the culture and windowsidentity here; they will be correct
   System.Threading.ThreadPool.QueueUserWorkItem(AddressOf Testing, new Object)
End Sub

Private Sub Testing(state As Object)
   ' Observe the culture and windowsidentity here; they will not be what we need them to be
End Sub
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T21:33:30+00:00Added an answer on May 26, 2026 at 9:33 pm

    This method signature:

    public static bool QueueUserWorkItem(
        WaitCallback callBack,
        Object state
    )
    

    Accepts a state object. This can be an instance of a class that hold your user’s culture and whatever other items you need to persist. This information is propagated back into the callback method, where you can cast it back to an instance of your class.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm building UI logging into a long-existing ASP.NET enterprise application. I have my own
I have an asp.net application that requires some editing of the machine.config file in
I have an ASP.Net application that takes an unusually long time to start up
We have an ASP.NET application that users use to generate certain reports. So far
We have an ASP.NET application that uses SQL Server to store its session state.
I have an ASP.NET application that is fairly basic. It queries some data and
I have an asp.net application that utilizes long polling. So, a typical call to
I have an ASP.Net application that needs needs to have some work performed by
I have an ASP.NET application that is hosted in timezone A and is being
I have an ASP.NET application that uses a custom .NET library (a .DLL file).

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.