Still Problems with Thread Impersonation

M

Matthias Wohlmann

Hi,
I already posted to this newsgroup, but didn't get an answer. So I try
again:

I've got an ASP.NET Web-Application written in C#.
In IIS 6.0 (Windows Server 2003) I have set the application to allow
anonymous access (using the default Account IUSR_<servername>). In
Web.config I have set
<identity impersonate="true" userName=<myUser> password=<myPWD>/>

Everything works fine exept for this:
In my application, I start a thread. I know that impersonation is not
taken over by the thread so I copy the current impersonation by

System.IntPtr windowsIdentityToken;
System.IntPtr newToken = System.IntPtr.Zero;
WindowsIdentity currentIdentity = WindowsIdentity.GetCurrent();
DuplicateToken(currentIdentity.Token, 2, ref newToken);
this.windowsIdentityToken = newToken;

and inside the thread I re-impersonate with:

WindowsImpersonationContext impersonatedUser =
WindowsIdentity.Impersonate(this.windowsIdentityToken);

After that, access to files inside the thread is working, but two things
don't work:

- Sending Mails: I get this error:
System.Web.HttpException: Could not create 'CDO.Message' object.
on Command:
System.Web.Mail.SmtpMail.Send(msg);

- I also use encryption inside the thread. Command
SymmetricAlgorithm symm = new TripleDESCryptoServiceProvider();
leads to Exception:
System.Security.Cryptography.CryptographicException: Cryptographic
service provider (CSP) could not be found for this algorithm.

- Other accesses of COM-Objects also don't work...

If I don't impersonate the thread by commenting out
//WindowsImpersonationContext impersonatedUser =
WindowsIdentity.Impersonate(this.windowsIdentityToken);
both commands work, but the thread can't access some files I need.

does anyone have any idea?

Thanks,
matthias
 

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,995
Messages
2,570,230
Members
46,819
Latest member
masterdaster

Latest Threads

Top