ASPNET and Impersonation

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

  1. #1

    Default Re: ASPNET and Impersonation

    Maybe someone the aspnet.security group has some other suggestions.

    Shel

    --
    This posting is provided "AS IS" with no warranties, and confers no rights.
    Use of included script samples are subject to the terms specified at
    [url]http://www.microsoft.com/info/cpyright.htm[/url]


    "Charles Leonard" <elmsdn13@hotmail.com> wrote in message
    news:125001c372fe$50b429f0$a101280a@phx.gbl...
    > In case anyone is interested, the solution to the above
    > problem appears to be that there is no solution-at least
    > not through any additional configuration using the
    > Web.config file.
    >
    > There is some hint of achieving such authorization
    > programmatically using "advapi32.dll" and the LogonUser()
    > API. However, there is a suggestion that any such code
    > may not work on all platforms.
    >
    > In any event, I took another approach to solve the
    > problem. By modifying the Machine.config file (in the
    > directory C:\WINDOWS\Microsoft.NET\Framework\v1.1.4322
    > \CONFIG) and changing the <processModel> contents of
    > userName and password from the default settings to the
    > userName and password references I had previously defined
    > for the <identity> tag of my Web.config file, the identity
    > problem with thread creation is resolved and access to
    > the "shared drive" is achieved by both threads without
    > further incident.
    >
    > The unfortunate drawback in this approach is that the
    > process identity for all .Net applications installed on
    > the machine will be the one defined in the Machine.config
    > file (instead of being localized to the single Web Service
    > being configured by the Web.config file).
    >
    > If anyone does find away to achieve Impersonation that
    > actually can be applied to all threads created by the
    > target web service (and/or configured by the Web.config
    > file), let me know. And for that matter, if anyone has a
    > better suggestion on how to access a shared drive without
    > using Impersonation or changing the process identity, I'd
    > be very interested in this as well.
    >
    > Thanks.
    >
    > --Charles Leonard
    >
    > References:
    >
    > [url]http://www.15seconds.com/Issue/030115.htm?voteresult=5[/url]
    > [url]http://support.microsoft.com/default.aspx?[/url]
    > scid=http://support.microsoft.com:80/support/kb/articles/q3
    > 17/0/12.asp&NoWebContent=1
    > [url]http://msdn.microsoft.com/library/default.asp?[/url]
    > url=/library/en-us/vsent7/html/vxconimpersonation.asp
    > [url]http://www.msdnaa.net/Resources/Display.aspx?ResID=641[/url]
    > [url]http://support.microsoft.com/default.aspx?[/url]
    > scid=http://support.microsoft.com:80/support/kb/articles/q3
    > 06/1/58.asp&NoWebContent=1
    > [url]http://www.codeproject.com/csharp/cpimpersonation1.asp[/url]
    > [url]http://www.codeproject.com/csharp/lsadotnet.asp[/url]
    >
    >
    > >-----Original Message-----
    > >OK. So just when I think I am making progress, 2 steps
    > >forward, I am thrown another curve ball, one step
    > >backwards. I am employing impersonation for my Web
    > >Service. Impersonation is being used because of a
    > >requirement that we have to access a "shared drive."
    > >
    > >Here is what I have done:
    > >
    > >1. aspnet_setreg.exe has been used to encrypt my
    > > credentials.
    > >2. Web.config has been edited to include:
    > >
    > ><identity impersonate="true"
    > >
    > >userName="registry:HKLM\SOFTWARE\MySoftware\ident ity\ASPNE
    > T
    > >_SETREG,userName"
    > >
    > >password="registry:HKLM\SOFTWARE\MySoftware\ident ity\ASPNE
    > T
    > >_SETREG,password"
    > > />
    > >
    > >So far, so good. When I run my web service, the
    > >impersonation happens. Which is great-except for one
    > >thing. My web service creates a thread. The thread must
    > >also access the same network share. Unfortunately, the
    > >thread is reverting back to the "ASPNET" user despite the
    > >Web.config settings.
    > >
    > >Does anyone know how to correct this problem?
    > Preferably,
    > >I'd like to correct it through configuration settings, if
    > >possible, rather than programmatically. But, I will
    > >welcome all suggestions.
    > >
    > >Thanks.
    > >
    > >--Charles Leonard
    > >
    > >.
    > >

    Shel Blauman [MSFT] Guest

  2. Similar Questions and Discussions

    1. ASPNET Account, Impersonation, SQL Server problem
      Does --------- No, the general mis conception is that it does need to be a domain account. But, in fact it doesn't. There are a lot of...
    2. User ASPNET
      I have a share in other computer and I want access to that sahre with my web application. For that I do: - Create a User ASPNET in my domain - Use...
    3. Restricting ASPNET ACLs without breaking ASPNET (newbie-ish)
      Scenario: We have a library with objects that host Jscript for the execution of complex validation code. This library is being called by an ASP.NET...
    4. Impersonation in ASPNET and LogonUser
      Have you taken a look at the asp.net security best practices paper? It discusses some of the pitfalls and issues when using impersonation....
    5. ASPNET: VS CF
      We were using ColdFusion for our Intranet in the past. We just moved to ASP.Net for our new development. In my opinion, ASP.Net is much more...
  3. #2

    Default Re: ASPNET and Impersonation

    Well sounds to me like this should be easy...but then again, I can't see all
    the messages of this thread. Try the following, grab the Token from your
    current thread and call the API ImpersonateLoggedOnUser from the new thread.
    I've recently done this for a similar problem and it works well. My
    suggestion is for you to read up on how .NET in general handles security and
    it will clarify things for you...at least it did for me. The CLR is a
    mystical little piece of technology ;)

    You should also follow my last post, I asked the ASPNET team if this will
    cause some major bad stuff to occur in their process. My current tests seem
    good.

    Token -> System.Security.Principal.WindowsIdentity.GetCurre nt.Token.ToInt32

    ImpersonateLoggedOnUser -> Look it up in MSDN...really simple to
    call...Don't forget to RevertToSelf.


    Hope this helps,

    Lior

    "Shel Blauman [MSFT]" <sheldonb@online.microsoft.com> wrote in message
    news:#D#vPuwcDHA.1744@TK2MSFTNGP12.phx.gbl...
    > Maybe someone the aspnet.security group has some other suggestions.
    >
    > Shel
    >
    > --
    > This posting is provided "AS IS" with no warranties, and confers no
    rights.
    > Use of included script samples are subject to the terms specified at
    > [url]http://www.microsoft.com/info/cpyright.htm[/url]
    >
    >
    > "Charles Leonard" <elmsdn13@hotmail.com> wrote in message
    > news:125001c372fe$50b429f0$a101280a@phx.gbl...
    > > In case anyone is interested, the solution to the above
    > > problem appears to be that there is no solution-at least
    > > not through any additional configuration using the
    > > Web.config file.
    > >
    > > There is some hint of achieving such authorization
    > > programmatically using "advapi32.dll" and the LogonUser()
    > > API. However, there is a suggestion that any such code
    > > may not work on all platforms.
    > >
    > > In any event, I took another approach to solve the
    > > problem. By modifying the Machine.config file (in the
    > > directory C:\WINDOWS\Microsoft.NET\Framework\v1.1.4322
    > > \CONFIG) and changing the <processModel> contents of
    > > userName and password from the default settings to the
    > > userName and password references I had previously defined
    > > for the <identity> tag of my Web.config file, the identity
    > > problem with thread creation is resolved and access to
    > > the "shared drive" is achieved by both threads without
    > > further incident.
    > >
    > > The unfortunate drawback in this approach is that the
    > > process identity for all .Net applications installed on
    > > the machine will be the one defined in the Machine.config
    > > file (instead of being localized to the single Web Service
    > > being configured by the Web.config file).
    > >
    > > If anyone does find away to achieve Impersonation that
    > > actually can be applied to all threads created by the
    > > target web service (and/or configured by the Web.config
    > > file), let me know. And for that matter, if anyone has a
    > > better suggestion on how to access a shared drive without
    > > using Impersonation or changing the process identity, I'd
    > > be very interested in this as well.
    > >
    > > Thanks.
    > >
    > > --Charles Leonard
    > >
    > > References:
    > >
    > > [url]http://www.15seconds.com/Issue/030115.htm?voteresult=5[/url]
    > > [url]http://support.microsoft.com/default.aspx?[/url]
    > > scid=http://support.microsoft.com:80/support/kb/articles/q3
    > > 17/0/12.asp&NoWebContent=1
    > > [url]http://msdn.microsoft.com/library/default.asp?[/url]
    > > url=/library/en-us/vsent7/html/vxconimpersonation.asp
    > > [url]http://www.msdnaa.net/Resources/Display.aspx?ResID=641[/url]
    > > [url]http://support.microsoft.com/default.aspx?[/url]
    > > scid=http://support.microsoft.com:80/support/kb/articles/q3
    > > 06/1/58.asp&NoWebContent=1
    > > [url]http://www.codeproject.com/csharp/cpimpersonation1.asp[/url]
    > > [url]http://www.codeproject.com/csharp/lsadotnet.asp[/url]
    > >
    > >
    > > >-----Original Message-----
    > > >OK. So just when I think I am making progress, 2 steps
    > > >forward, I am thrown another curve ball, one step
    > > >backwards. I am employing impersonation for my Web
    > > >Service. Impersonation is being used because of a
    > > >requirement that we have to access a "shared drive."
    > > >
    > > >Here is what I have done:
    > > >
    > > >1. aspnet_setreg.exe has been used to encrypt my
    > > > credentials.
    > > >2. Web.config has been edited to include:
    > > >
    > > ><identity impersonate="true"
    > > >
    > > >userName="registry:HKLM\SOFTWARE\MySoftware\ident ity\ASPNE
    > > T
    > > >_SETREG,userName"
    > > >
    > > >password="registry:HKLM\SOFTWARE\MySoftware\ident ity\ASPNE
    > > T
    > > >_SETREG,password"
    > > > />
    > > >
    > > >So far, so good. When I run my web service, the
    > > >impersonation happens. Which is great-except for one
    > > >thing. My web service creates a thread. The thread must
    > > >also access the same network share. Unfortunately, the
    > > >thread is reverting back to the "ASPNET" user despite the
    > > >Web.config settings.
    > > >
    > > >Does anyone know how to correct this problem?
    > > Preferably,
    > > >I'd like to correct it through configuration settings, if
    > > >possible, rather than programmatically. But, I will
    > > >welcome all suggestions.
    > > >
    > > >Thanks.
    > > >
    > > >--Charles Leonard
    > > >
    > > >.
    > > >
    >
    >

    Lior Amar 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