C# 3.5 ASP.net File IO issue, UnauthorizedAccessException to file on network share


I get an UnauthorizedAccessException everytime I try to access (just read) a file on a network share "\\server\folder1\folder2\file.pdf."

I am impersonating the domain\aspnet user which has read & write access to the above mentioned folders. The file is not read-only.

I tried finding the permissions via System.Security.Permissions.FileIOPermission. It just says NoAccess to all files.

I'm not sure what else I can do.

I am using Visual Studio 2008, ASP.net 2.0 on Framework 3.5, WinXP, IIS 5.1.

Best Solution

ASP.NET user will not work with network path. So you need to have a windows account that will have all the rights and then you need to imposernate things in web.config like following.

<identity impersonate="true" userName="domainname\windowuseraccount" password="password"/>
Related Question