How can I impersonate a user in code?



Hi all,

I'm trying to save an uploaded file to a share on another computer in the
domain. If I use the <identity impersonate ..... /> tag in the web.config
and enter the credentials of a domain user which has sufficient rights on
that share it works fine.

However I don't need (and want) to run the complete site under this user, I
only need to impersonate the moment I'm trying to save the file. I've tried
to achieve this is code by creating a WindowsIdentity object and
impersonating it but that isn't working (NotSupported Exception). The code
works fine in a sample winapp but apparantly a webapp doesn't like it.

Does anyone have an idea on how I can achieve the impersonation in code?

TIA,
Friso Wiskerke


.



Relevant Pages

  • Re: Security
    ... web.config file to impersonate a domain user that has access to the database ... registry the domain user and password. ... have Windows Integrated Security set. ... user while running the code under the impersonated account. ...
    (microsoft.public.dotnet.framework.aspnet)
  • Client-side application and impersonation
    ... Can a browser-based cient-side application impersonate a domain user? ... I am trying to host a client-side assembly in a browser. ...
    (microsoft.public.dotnet.framework.aspnet)
  • Impersonation - as a specific user for all requests
    ... I'd like to impersonate all requests as a specific domain user. ... I want all requests to impersonate the same domain username/password. ...
    (microsoft.public.dotnet.framework.aspnet.security)
  • Re: Application Pool without Anonymous Access
    ... Does the user account being used to run the app pool have "impersonate a ... user after authetication" user right. ... any domain user to log in. ...
    (microsoft.public.inetserver.iis.security)