I have an Application running in a server, that takes a username and file path. The idea to check if the user can read the file (the target user is not the same user running the program).

So how to check read permissions for specific user ??

有帮助吗?

解决方案

I can't take responsibility for this as I googled it and the answer was by James Newton-King found here- How to present credentials in order to open file?


You want to impersonate a user who does have the rights to access the file.

I recommend using a class like this - http://www.codeproject.com/KB/cs/zetaimpersonator.aspx. It hides all the nasty implementation of doing impersonation.

using (new Impersonator("myUsername", "myDomainname", "myPassword"))
{
  string fileText = File.ReadAllText("c:\test.txt");
  Console.WriteLine(fileText);
}

其他提示

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top