Copy Credentials for a worker thread

M

maa

In my web app I am creating threads to do work. I want to give the same
rights as my main asp.net thread. The default is to give lesser rights so
when I access the db I get a log on failure with a trusted connection or a
user name/password.
What is the std way to copy credentials in asp.net?

Thanks,
maa
 
S

S. Justin Gengo

maa,

I think this will take care of what you're looking for. It's an excerpt from
the MSDN article found here:
http://support.microsoft.com/kb/306158


Impersonate the Authenticating User in Code
To impersonate the authenticating user (User.Identity) only when you run a
particular section of code, you can use the code to follow. This method
requires that the authenticating user identity is of type WindowsIdentity.

Visual Basic .NET
Dim impersonationContext As
System.Security.Principal.WindowsImpersonationContext
Dim currentWindowsIdentity As System.Security.Principal.WindowsIdentity

currentWindowsIdentity = CType(User.Identity,
System.Security.Principal.WindowsIdentity)
impersonationContext = currentWindowsIdentity.Impersonate()

'Insert your code that runs under the security context of the authenticating
user here.

impersonationContext.Undo()

Visual C# .NET
System.Security.Principal.WindowsImpersonationContext impersonationContext;
impersonationContext =
((System.Security.Principal.WindowsIdentity)User.Identity).Impersonate();

//Insert your code that runs under the security context of the
authenticating user here.

impersonationContext.Undo();


Regards,

S. Justin Gengo, MCP

Free code and component libraries at:
http://www.aboutfortunate.com
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top