简体   繁体   中英

Setting permissions of uploaded file to allow reading in ASP.NET

I have an ASP.NET web application in which I am trying to open a text file located within a subdirectory of my webroot. The text file was uploaded through the same web application using SAFileUp. I am using the FileInfo object as such to read the text file ...

Response.TransmitFile(fileInfo.FullName)

The puzzling thing is I get an exception thrown when I execute this line of code.

Access to the path 'C:\webroot\xxxx\uploads\filename.txt' is denied 

I have given the uploads folder, where the text file was uploaded, read/write/execute permissions to both the IUSR and IIS_IUSRS account and the permissions have inherited to the sub folders below. The interesting thing is the actual text document I am trying to load has NO permissions set for IIS_IUSRS while IUSR does have read/write/execute. As soon as I add the "read" permission to IIS_IUSRS I am able to read the file.

What confuses me is I would have thought the file would have inherited the permissions from the parent folders, but apparently not. How do I set the permissions of the uploaded file during the upload process so I can open it later for reading?

Well .. I found the answer. Basically, the upload component SAFileUp, uses the "Temp" directory where the uploaded file is cached to set the permissions of the uploaded file. In my case this directory was C:\\Windows\\temp . All I did was give the account IIS_IUSRS READ access to the C:\\Windows\\temp directory and I was able to access the uploaded file without issue.

Here is an article on SoftArtisans's website that clued me in and helped me find the directory the uploaded file was cached to.

http://support.softartisans.com/kbview_776.aspx

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM