June 24, 2005
From what I understand, you are looking to create an impersonation
context from the web application's USER and Not the local web application's
service account. In this case, the easiest way would be to disable anonymous
auth in IIS & enable Windows Int. Auth and to disable anonymous auth in the
web.config. You do Not need to put the impersonation=true element in though.
Then use the code:
Dim context as windowsimpersonationcontext
context = USER.identity.impersonate
'do something
context.undo
User is a WindowsPrincipal object which contains the web application's user
identity and Not the service account of the application. You can use the
Identity.impersonate from it. I'm not quite sure what the usertoken you are
wanting is needed for, but I do believe that somewhere under User.Identity.
there is a usertoken property. This should work, and I hope this helps!

Let me know how it turns out!
--
Joseph Bittman
Microsoft Certified Application Developer
"Web Developer" <> wrote in message
news:9989FB8F-D192-40C8-ADA7-...
>I have an ASP.Net web application that uses Integrated Authentication. I'd
> like to impersonate the person making the request at RUNTIME instead of
> specifying impersonate="true" in the web.config.
>
> Does anyone know how I can get the requesting user's userToken to pass to
> the Impersonate method of the
> System.Threading.Thread.CurrentPrincipal.Identity?
>
> i.e.
> 'Retrieve the requesting user's security token
> Dim userToken as IntPtr = /Some call here/
>
> Dim MyImpersonationContext As
> System.security.Principal.WindowsImpersonationCont ext
>
> 'Temporarily impersonate the requesting user
> MyImpersonationContext =
> CType(System.Threading.Thread.CurrentPrincipal.Ide ntity(),
> System.Security.Principal.WindowsIdentity).Imperso nate(userToken)
>
> 'Call a web service with using the logged-on user's credentials
>
> 'Revert the impersonation
> MyImpersonationContext.Undo()
>
> Thanks for your help!