Impersonation fails when accessing remote files.

Ask a Question related to ASP.NET Security, Design and Development.

  1. #1

    Default Impersonation fails when accessing remote files.

    I am impersonating a user by setting the details in Web.config. I have
    confirmed that the .aspx page is running as the impersonated user. I then
    try to access a remote file which requires authentication to view.

    The log files for the remote server say that user "aspnet" tried to
    connect and was (rightly) rejected.

    After lots of fiddling and Googling I discovered the following:

    [url]http://support.microsoft.com/default.aspx?scid=kb;EN-US;q325791[/url]

    So I changed my page definition to include aspcompat="true". The problem
    is still the same - the page will not try to connect using the
    impersonated user credentials.

    To clarify:
    Impersonation is working but the impersonated user credentials are not
    being used in the authenication process.

    Any ideas?

    simonc Guest

  2. Similar Questions and Discussions

    1. ASP.NET Impersonation fails on IIS
      Hi, I built an ASP.NET Web application with impersonation. This works fine, my login is recognized. Now I want to get access to a certain folder...
    2. Impersonation failing when accessing another assembly
      Hi, I've written an ASP.NET web service which impersonates a user designated by the end user, then calls into another .NET assembly to copy a file...
    3. #26316 [Bgs]: Accessing remote php files (xml header) with xslt doesn't get session variables
      ID: 26316 User updated by: andrew at shh dot fi Reported By: andrew at shh dot fi Status: Bogus Bug Type: ...
    4. #26316 [Opn->Bgs]: Accessing remote php files (xml header) with xslt doesn't get session variables
      ID: 26316 Updated by: sniper@php.net Reported By: andrew at shh dot fi -Status: Open +Status: Bogus...
    5. #26316 [NEW]: Accessing remote php files (xml header) with xslt doesn't get session variables
      From: andrew at shh dot fi Operating system: windows xp PHP version: 4.3.3 PHP Bug Type: XSLT related Bug description: ...
  3. #2

    Default Re: Impersonation fails when accessing remote files.

    On Mon, 08 Nov 2004 05:38:28 -0500, "simonc" <simon.c@gordian.co.uk> wrote:

    ¤ I am impersonating a user by setting the details in Web.config. I have
    ¤ confirmed that the .aspx page is running as the impersonated user. I then
    ¤ try to access a remote file which requires authentication to view.
    ¤
    ¤ The log files for the remote server say that user "aspnet" tried to
    ¤ connect and was (rightly) rejected.
    ¤
    ¤ After lots of fiddling and Googling I discovered the following:
    ¤
    ¤ [url]http://support.microsoft.com/default.aspx?scid=kb;EN-US;q325791[/url]
    ¤
    ¤ So I changed my page definition to include aspcompat="true". The problem
    ¤ is still the same - the page will not try to connect using the
    ¤ impersonated user credentials.
    ¤
    ¤ To clarify:
    ¤ Impersonation is working but the impersonated user credentials are not
    ¤ being used in the authenication process.

    Web server impersonation with .NET is limited to local web server resources. You need to use
    Delegation if you're accessing a resource on another server:

    [url]http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vsent7/html/vxconaspnetdelegation.asp[/url]

    The other solution is to implement impersonation using the LogonUser API function call:

    [url]http://support.microsoft.com/?id=306158[/url]


    Paul ~~~ [email]pclement@ameritech.net[/email]
    Microsoft MVP (Visual Basic)
    Paul Clement Guest

  4. #3

    Default Re: Impersonation fails when accessing remote files.

    Paul,
    thanks for the prompt reply. I have already tried using the logon user API
    and the result is the same - IE the credentials used to logon are the
    aspnet ones not the impersonated ones. Here's the code (Impersonate is
    just a wrapper class for the MS standard example of using the logon user
    API):

    '**** CODE ****
    Dim impersonation As Impersonate = New Impersonate

    'WhoAmI - will be 'aspnet'
    Dim userStr As String = impersonation.WhoAmI

    impersonation.SetIdentity(user, pass, domain)
    impersonation.BeginImpersonation()

    'WhoAmI - will be 'user'
    userStr = impersonation.WhoAmI

    Dim myFileWebResponse As System.Net.FileWebResponse

    Try
    Dim url As String = _
    "file://192.168.0.1\path\test.pdf"
    Dim myFileWebRequest As System.Net.FileWebRequest = _
    CType(System.Net.WebRequest.Create(url), _
    System.Net.FileWebRequest)

    'This call will fail with an access denied exception.
    'Server logs show that user 'aspnet' tried to connect.
    myFileWebResponse = _
    CType(myFileWebRequest.GetResponse(), _
    System.Net.FileWebResponse)
    Catch ex As System.Net.WebException

    Catch ex As UriFormatException

    End Try

    impersonation.EndImpersonation()

    'WhoAmI - back to 'aspnet'
    userStr = impersonation.WhoAmI
    '***** END CODE ******

    I guess I'll have to look into delegation...

    simonc Guest

  5. #4

    Default Re: Impersonation fails when accessing remote files.

    I gues you will. A quote from the Platform SDK about LogonUser function
    "The LogonUser function attempts to log a user on to the local computer. The
    local computer is the computer from which LogonUser was called. You cannot
    use LogonUser to log on to a remote computer."

    About ASPCOMPAT=TRUE. This setting effectively switches processing threads to
    STA mode (hence ASPCOMPAT). I'd not reccomend doing that unless you are
    creating (explicit or implicit) some STA COM components in your ASP.NET code.

    "simonc" wrote:
    > Paul,
    > thanks for the prompt reply. I have already tried using the logon user API
    > and the result is the same - IE the credentials used to logon are the
    > aspnet ones not the impersonated ones. Here's the code (Impersonate is
    > just a wrapper class for the MS standard example of using the logon user
    > API):
    >
    > '**** CODE ****
    > Dim impersonation As Impersonate = New Impersonate
    >
    > 'WhoAmI - will be 'aspnet'
    > Dim userStr As String = impersonation.WhoAmI
    >
    > impersonation.SetIdentity(user, pass, domain)
    > impersonation.BeginImpersonation()
    >
    > 'WhoAmI - will be 'user'
    > userStr = impersonation.WhoAmI
    >
    > Dim myFileWebResponse As System.Net.FileWebResponse
    >
    > Try
    > Dim url As String = _
    > "file://192.168.0.1\path\test.pdf"
    > Dim myFileWebRequest As System.Net.FileWebRequest = _
    > CType(System.Net.WebRequest.Create(url), _
    > System.Net.FileWebRequest)
    >
    > 'This call will fail with an access denied exception.
    > 'Server logs show that user 'aspnet' tried to connect.
    > myFileWebResponse = _
    > CType(myFileWebRequest.GetResponse(), _
    > System.Net.FileWebResponse)
    > Catch ex As System.Net.WebException
    >
    > Catch ex As UriFormatException
    >
    > End Try
    >
    > impersonation.EndImpersonation()
    >
    > 'WhoAmI - back to 'aspnet'
    > userStr = impersonation.WhoAmI
    > '***** END CODE ******
    >
    > I guess I'll have to look into delegation...
    >
    >
    vetplakh Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139