문제

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