1

I'm using Windows Server 2008 and IIS 7.5 I'm trying to access a file this way: \server\C$\temp\testFile.log from C# code running on another server.

My username is an admin on both servers. The code is running under that account. The temp folder has been set to full rights for (my user) and ASP.NET.

Why can't I access it?

I can't do a shared folder; against the rules. I am already running under full account; therefore, I don't need to do impersonation, right?

Dave H
  • 653
  • 12
  • 22
user1019042
  • 2,428
  • 9
  • 43
  • 85

3 Answers3

3

Had this very same problem a while ago.

For your debug process to run with full Admin access, you'd have to open Visual Studio with full admin access.

In production, have your process "Run As Administrator".

If you do not do any of the above, you will have to implement impersonation.

Adriano Carneiro
  • 57,693
  • 12
  • 90
  • 123
1

Is this a web app? Are you sure the app is impersonating your account? Is anonymous access set to true in IIS?

AnotherDeveloper
  • 1,242
  • 1
  • 15
  • 36
  • You said: Are you sure the app is impersonating your account? Yes, I have tried impersonation, even though I didn't think I need it, based on this link: http://support.microsoft.com/kb/306158#3. But when I saw your: "are you sure," it made me revisit and bumped on another link that gave me the correct impersonation: http://stackoverflow.com/questions/125341/how-do-you-do-impersonation-in-net (check Matt Johnson's answer). His solution worked like a charm! So you kind of steered me the right direction. Thank you! Note: the solution works even if IIS anonymous setting is set to false! – user1019042 Jul 18 '13 at 13:46
  • Awesome! Glad I could play some (if even very very minor) part in you getting the solution you needed. I only answered because those two things have come back to haunt me time and time again. – AnotherDeveloper Aug 15 '13 at 15:25
0

This seems to be a known problem. Typical solutions use WNetUseConnection.

See

  1. Accessing a Shared File (UNC) From a Remote, Non-Trusted Domain With Credentials
  2. WNetUseConnection connects to remote server/UNC on same domain but not to a different/remote domain

But my first guess would be to check FileIOPermission as discussed in Testing a UNC Path's “Accessability”

Community
  • 1
  • 1
mkoertgen
  • 898
  • 6
  • 14