Jamo Jamo - 11 days ago 6
C# Question

Required user for ThreadPool.QueueUserWorkItem

Maybe this question doesn't go here....

I am using

ThreadPool.QueueUserWorkItem
to write a folder/file, my problem is when it tries to write I got
UnauthorizedAccessException
.

So I changed the directory to grant everyone to write and it works.

But I don't want to grant everyone to write. It seems is a different user/group that the
ThreadPool.QueueUserWorkItem
uses than the main thread.

What user should it be?

Answer

Because it is a IIS application the user you have to grant rights to is the user the application pool runs under.

Your main thread is likey impersonating the user that the request is for. The background work item is nolonger associated with the user.

PS: using ThreadPool.QueueBackgroundWorkItem in IIS is a very bad idea, you need to use a more appropriate tool for background work in IIS.

Comments