Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / CLR / February 2005

Tip: Looking for answers? Try searching our database.

Impersonate in ThreadPool

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Viorel Ghilas - 03 Feb 2005 08:10 GMT
Hi all

I have an ASP.NET application that uses impersonate account to connect to
DB, this works good. But in some cases I need to put some methods in
ThreadPool. The methods from ThreadPool should do some foreground operations
with DB. But .NET throws me the sql exception "Login failed for user
'(null)'. Reason: Not associated with a trusted SQL Server connection.". The
thread from pool in execution proccess has an ASPNET account different from
my impersonated account. How can I resolve this problem, do you have any
suggestions?

with best regards
Viorel
Pavel Lebedinsky - 08 Feb 2005 04:25 GMT
Some thread pool implementations pass the impersonated token
to the thread pool thread, others do not. Based on the behavior
you're seeing it looks like the current .NET implementation
doesn't.

You can always do this yourself though. In the unmanaged world
you would do something like this:

1. hCurrentToken = OpenThreadToken
2. hDupToken = DuplicateToken(hCurrentToken)
3. Pass hDupToken as a parameter to your thread pool
work item

When your work item starts, it does this:

1. hThreadPoolToken = OpenThreadToken
2. SetThreadToken(hDupToken)
3. Perform the work
4. SetThreadToken(hThreadPoolToken)
5. CloseHandle(hDupToken)

You should be able to do something like this in .NET with
classes like WindowsIdentity. It even has a constructor that
takes a token handle as IntPtr. But I have no idea whether it
duplicates the token internally, whose responsibility it is to
close the handle etc. You might have to experiment a little
to find out how to use it properly.

> I have an ASP.NET application that uses impersonate account to connect to
> DB, this works good. But in some cases I need to put some methods in
[quoted text clipped - 7 lines]
> my impersonated account. How can I resolve this problem, do you have any
> suggestions?
Gaurav Khanna - 09 Feb 2005 07:22 GMT
Check this -
http://geekswithblogs.net/khanna/archive/2005/02/09/22441.aspx

Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.