I'm trying to run a method on the loading of a page which will search through a network shared folder and do a particular operation on all .tif files found. Problem is I'm getting an error:
DirectoryInfo dir = new DirectoryInfo(directory);
FileInfo[] tifs = dir.GetFiles("*.tif", SearchOption.AllDirectories); //Throws error.
Exception Details: System.UnauthorizedAccessException: Access to the path '\server\sharename\folder\subfolder' is denied.
ASP.NET is not authorized to access the requested resource. Consider granting access rights to the resource to the ASP.NET request identity. ASP.NET has a base process identity (typically {MACHINE}\ASPNET on IIS 5 or Network Service on IIS 6) that is used if the application is not impersonating. If the application is impersonating via , the identity will be the anonymous user (typically IUSR_MACHINENAME) or the authenticated request user.
To grant ASP.NET access to a file, right-click the file in Explorer, choose "Properties" and select the Security tab. Click "Add" to add the appropriate user or group. Highlight the ASP.NET account, and check the boxes for the desired access.
I've tried foll开发者_运维知识库owing these instructions, but I'm not able to add the specified account to the share's permissions. What am I doing wrong?
See Related Question: Trouble accessing network share from asp.net web form
You probably need to impersonate a user that does have access: see http://msdn.microsoft.com/en-us/library/xh507fc5%28v=VS.90%29.aspx
精彩评论