質問

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