Running a section of code under a specific account

G

Guest

Hi all

I’m trying to write a file to a different sever on the same domain then the server hosting the site, but the IIS user does not have access to the other server. I thought I would use impersonation to force the specific code to impersonate a user that does have the necessary permission with the code bellow. Unfortunately This code results in an "Unable to Logon" error as the System.Security.Principal.WindowsIdentity constructor expects a Windows account token and I been unable to determine how to do this Any ideas on how to achieve this?

Private Sub PerformTask(
Dim sUsers As String = "
Dim objImpersonatedIdentity As New System.Security.Principal.WindowsIdentity("Bill"
Dim MyImpersonation As System.Security.Principal.WindowsImpersonationContext = objImpersonatedIdentity.Impersonat
sUsers = objImpersonatedIdentity.Name(
MyImpersonation.Undo(
lblOutPut.Text = sUser
End Su

Thanks in advanc

Jak
 
M

Martin Dechev

Hi, Jake,

Try the code examples in this article:

http://support.microsoft.com/?kbid=306158

Greetings
Martin
Jake said:
Hi all,

I’m trying to write a file to a different sever on the same domain then
the server hosting the site, but the IIS user does not have access to the
other server. I thought I would use impersonation to force the specific
code to impersonate a user that does have the necessary permission with the
code bellow. Unfortunately This code results in an "Unable to Logon" error
as the System.Security.Principal.WindowsIdentity constructor expects a
Windows account token and I been unable to determine how to do this Any
ideas on how to achieve this?
Private Sub PerformTask()
Dim sUsers As String = ""
Dim objImpersonatedIdentity As New System.Security.Principal.WindowsIdentity("Bill")
Dim MyImpersonation As
System.Security.Principal.WindowsImpersonationContext =
objImpersonatedIdentity.Impersonate
 

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,743
Messages
2,569,478
Members
44,899
Latest member
RodneyMcAu

Latest Threads

Top