Running a section of code under a specific account

Discussion in 'ASP .Net' started by =?Utf-8?B?SmFrZQ==?=, Apr 27, 2004.

  1. 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
     
    =?Utf-8?B?SmFrZQ==?=, Apr 27, 2004
    #1
    1. Advertising

  2. Hi, Jake,

    Try the code examples in this article:

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

    Greetings
    Martin
    "Jake" <> wrote in message
    news:...
    > 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
    > sUsers = objImpersonatedIdentity.Name()
    > MyImpersonation.Undo()
    > lblOutPut.Text = sUsers
    > End Sub
    >
    > Thanks in advance
    >
    > Jake
    >
    >
     
    Martin Dechev, Apr 27, 2004
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?bWdvbnphbGVzMw==?=

    2.0 - aspnet_wp running under domain account

    =?Utf-8?B?bWdvbnphbGVzMw==?=, Jun 19, 2006, in forum: ASP .Net
    Replies:
    0
    Views:
    384
    =?Utf-8?B?bWdvbnphbGVzMw==?=
    Jun 19, 2006
  2. Chad Dressler
    Replies:
    0
    Views:
    673
    Chad Dressler
    Dec 30, 2006
  3. carl

    running dos command under admin account

    carl, Aug 21, 2003, in forum: ASP .Net Security
    Replies:
    1
    Views:
    176
    Lewis Wang [MSFT]
    Aug 22, 2003
  4. Yehuda Vernik
    Replies:
    1
    Views:
    856
    Paul Clement
    Oct 19, 2004
  5. kampy
    Replies:
    9
    Views:
    371
    Steven D'Aprano
    Oct 19, 2012
Loading...

Share This Page