File.OpenRead access using UNC path. Impersonation not working?
Is there a reason Impersonation does not seem to work with a UNC path using File.OpenRead开发者_JS百科()? I'm utilizing CodeProject's Impersonation utility:
I have a user with rights to the share that I'm passing to OpenRead().
This is my code and it's not accessing the file:
try
{
bool canImp = imp.ImpersonateValidUser(impUser, domain, impPwd);
FileStream fs = File.OpenRead(filePath);
logger.Debug("File stream opened...");
byte[] b = new byte[fs.Length];
fs.Read(b, 0, b.Length);
fs.Close();
// code continued
Turns out I was using the IP address in my impersonation for the domain, rather than the friendly domain name. Once I used the friendly domain name, the impersonation worked.
精彩评论