The problem you have is that the code isn't actually doing anything - you
are impersonating the user that IIS is already using by
WindowsIdentity.GetCurrent();

You need to impersonate a user who has permissions on the directory.

On Thu, Feb 18, 2010 at 7:30 PM, Aaron <[email protected]> wrote:

> I'm working on an application and I need to determine if a directory
> exists or not.  I'm using the statements below:
>
> // strTempServerPath = folder path in the form of "\\servername\folder
> \"
> if (Directory.Exists(strTempServerPath))
> { ... }
>
> It works fine on my local machine but when I deploy to our web server,
> it always returns false.  I have checked and rechecked a dozen times
> to ensure that the directory is there.
>
> From what I can tell from my searches is that the network account
> doesn't have permissions to the folder.
>
> I've tried using WindowsImpersonationContext to try and get around it
> with no luck:
>
> System.Security.Principal.WindowsImpersonationContext
> impersonatinContext;
> WindowsIdentity identity = WindowsIdentity.GetCurrent();
> impersonatinContext = identity.Impersonate();
>
> Is there a way to get the application to use the credentials of the
> user and not the network account without the user having to provide
> password or having to explicitly grant the network account permissions
> on the folder?
>

Reply via email to