2

I'm attempting to access a network drive from an ASP.NET page. Technically it's a SharePoint application page (_layouts/mycompany/mypage.aspx) but I believe the principles are the same.

string filePath = @"\\companyshare\temp\test.txt";
FileStream fs = new FileStream(filePath, FileMode.Open, FileAccess.Read);

When I hit the second line in the code above I get the error:

Access to the path '\companyshare\temp\test.txt' is denied.

The application pool for this site is running under a domain account (MYCOMPANY\adminacct). MYCOMPANY\adminacct has access to the file \companyshare\temp\test.txt. I've confirmed that by logging into the server with the MYCOMPANY\adminacct credentials and navigating to the file using the same path that is in the code.

I'm running IIS 7.5

Questions

How come the above code is still getting access denied even though the application pool account has access to the folder and file?

Is there a way to confirm that my code is actually trying to access that file with the credentials I believe it is using?

4

1 に答える 1

1

デバッグするには、最初にweb.configで偽装を使用して、ASP.NETプロセスを自分自身として実行するか、保証できるアカウントがUNCファイルパスにアクセスできるようにします。

<identity impersonate="true" userName="yourDomain\yourAccountName" password="xyz" />

個人的には、IISアプリプールの資格情報よりもアプリケーションで偽装を使用することを選択しますが、それは私です。

これは、私が何度か使用したサーバープロセスのIDとデバッグに関する優れた記事です。

于 2012-05-23T19:27:08.467 に答える