Impersonate section of code
I'm am trying to impersonate a section of code that will write to the Registry. I'm using the code below:
Dim impersonationContext As System.Security.Principal.WindowsImpersonationCont ext
Dim currentWindowsIdentity As System.Security.Principal.WindowsIdentity
currentWindowsIdentity = CType(User.Identity, System.Security.Principal.WindowsIdentity)
impersonationContext = currentWindowsIdentity.Impersonate()
CreateRegKey("my value")
impersonationContext.Undo()
When this runs I get a "Specified cast is not valid." Error. The error occurs on the line with the CType Function.
Server is Windows 2003 AD, .NET 1.1, VStudio 2003
Thanks for any feedback.
|