I can't access unc path from C#. Getting access is denied

妖精的绣舞 提交于 2019-12-08 06:33:55

问题


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?


回答1:


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




回答2:


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.




回答3:


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”



来源:https://stackoverflow.com/questions/17708654/i-cant-access-unc-path-from-c-getting-access-is-denied

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!