Setting permissions of uploaded file to allow reading in ASP.NET - 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

Related

Wrong permissions when uploading file on WORDPRESS (Windows server 2012)

I've recently moved my WP site from godaddy to a physical sever using windows server 2012 R2.
But I'm having problem uploading files using the Admin panel, After uploading the file, I can see it physically on the server (wp-content\upload\2017\10)
But I can't see it on the website it self.
I can only see the file if I'm changing it permissions on the server it self.
I've changed the permissions to the folder, I gave full access to the relevant users. But still, it doesn't work for new files\pictures I'm uploading via the wp admin panel
Edit:
I've notice that every time I come to change the folder permissions the permissions under CREATOR OWNER are always empty, Is it Related ?
Thank you very much for the help
When you upload a file, PHP sends the file to a temporary directory on your server's hard drive (usually C:\Windows\Temp) and then copies it over to the proper directory. Once the file has is initially put in the temporary directory, it gets the permissions of that directory. The problem is when Windows moves that file to the proper place, it keeps the temporary directory’s permissions, which can cause access problems.
The way to fix this is to change the temporary directory to a folder within your WordPress installation, usually wp-content/upgrade.
To do this, follow these directions:
Find your php.ini file.
Find the upload_tmp_dir line, and change it to the wp-content/upgrade folder.
Browse to this folder and verify that the permissions are set properly.
You should then have the ability to properly view all your images. You'll most likely need to select all the previous selected images, and change the owner of the files to the web folder owner. Then you should be good to go!
If you can’t upload an image at all, it’s probably because you need to give the IUSR account Read/Write/Modify permission on your wp-content folder. This will allow you to upload, and do the WordPress & plugin updates.
Once you have done that, all you need to do is give the IIS_IUSRS group Read permissions on your “C:\Windows\Temp” folder.
Make sure to notice that the two permission changes you make are not for the same user/group. Give IUSR permissions on your wp-content folder and IIS_IUSRS permissions on your Windows temp folder.
Note: If you have edited your php.ini file and change the upload temp directory then you will need to give IIS_IUSRS group read permissions on that folder instead.
That should do it, or at least it worked for me.
http://chris.wastedhalo.com/2011/01/wordpress-upload-permissions-on-iis-7-fix/
I find myself coming back to this question time after time when images I add to the Media Gallery don't have the correct permissions in the WordPress Uploads folder. Since I develop WordPress sites locally, it would be a pain to set permission on the Uploads folder every time I work on a new site.
To fix this, I created a folder "C:\Websites\Temp" without messing around with permissions or security settings, etc. Then in MAMP, I edited the php.ini template of the PHP version I was using for this site, php7.3.0.ini (File, Edit Tempate, PHP). I then set upload_tmp_dir to "C:\Websites\Temp":
; Temporary directory for HTTP uploaded files (will use system default if not
; specified).
upload_tmp_dir = c:\websites\temp
and voila, no more permission issues.
Well, a few years later, found this post. Tried it. Failed.
Other solution is to assign a specific user to the site in IIS and apply the right permisions to the folder containing the site.

Change file permissions from code behind

I wonder if its possible to change permission on file from code behind?
PROBLEM: Unfortunately i use AjaxFileupload to upload files to webserver. So far so good. The problem arises when the uploaded files, that are saved on a mapped folder on the webserver are to be opened. The files doesnt show up in folder (on other server), lack of permissions.
Here is why: AjaxFileUpload save the file in a temp folder first, then move it to actual by me defined path. The file inherit the permission from that temp folder, not the permission i have put on my mapped folder. I need to use the mapped folder and I need the permissions on the mapped folder to be inherited to the file.
Why do i need this? I need this because there is an desktop application that need to open the files. The mapped folder have all the correct permissions for doing this. So, how to do? It would be easy if i can change permission on files from code behind, lets say just after i saved the file to folder, BUT is that even possible?
I read somewhere that it wasnt a good idea to change permission on the temp folder, any ideas why?
Any help would be appriciated!
edit:
So to clearify, i dont have any problems saving file to disk (server 3). My problem is that i cant see or access files on server 1, because the file doesn't inherit the mapped folder permissons. The mapped folder have permisson from both server 1 and server 3 but one the file get uploaded the file only have permission from server 3.
I don’t think the problem is with the permission on the source file. I believe the problem is the account used to run IIS does not have permission to access the mapped folder.
You can use Impersonation to grant access for the section of code that saves the file.
See these:
WindowsIdentity.Impersonate
This question
And this question
Solved it by myself. Basically wrote some code that gave me the name of the tempfolder on webserver where ajaxfileupload made the temp-save before moving the file to the folder i wanted it. When i had the name on that folder i basically changed permission on that folder. I only gave read and list permission on the folder because i dont want the desktop application to have any other right on the webserver. That was all i needed to get the file listed on in the mapped driver.

Give anonymous access to a folder under wp-admin folder in WordPress

I have a folder in wordpress which is located under the wp-admin folder and that folder contains the documents that can be downloaded from the user section.Now when the user downloads the words files using IE-9 and click on the open option from the IE save dialog it gives them a security warning. This problem is solved if I move the folder the root of the website. So I guess there is some access issue is there any way I can provide anonymous access to that folder. I really don't want to change the location of the folder as it will reqiure lots of changes to code and database.
FYI : This is issue comes only for word files , PDF files in the same folder work fine.
no you cannot access the folder without the username and password even when you try to grab the files of that folder using idm grabber or httrack you will need username and password

I can't watch videos I upload to drupal

I can upload a video to my drupal instance, but when I try to view the video I don't have rights to do so. I discovered that the IIS_IUSR doesn't have Read & Execute rights on the video even though the IIS_IUSR does on the containing directory.
IIS_IUSR has Read & Execute, List folder contents, and Read rights to the directory where files are uploaded to. However when I look at the rights of the uploaded video file (something.mp4), IIS_IUSR only has List folder/read data rights and Windows says these are inherited from the parent object. Include inheritable permissions from the object's parent option is checked.
Here's some more information that may be helpful.
If I try to access a video directly via a url I get this error:
HTTP Error 500.50 - URL Rewrite Module Error.
The page cannot be displayed because an internal server error has occurred.
Module RewriteModule
Notification BeginRequest
Handler StaticFile
Error Code 0x80070005
This seems like a configuration issue someplace, i.e. Drupal, IIS, or Windows.
Any thoughts.
My environment:
Windows 2008 R2
IIS 7.5
Drupal 6.19
MySQL 5.1.49
PHP 5.2.14
Someone requested that I post my .htaccess. There are several for the site, but here is the one for the files directory where the videos are uploaded to.
SetHandler Drupal_Security_Do_Not_Remove_See_SA_2006_006
Options None
Options +FollowSymLinks
But isn't .htaccess only used with Apache? I'm using IIS, so is the .htaccess even used?
Got the videos to work by changing the temp upload directory that Windows uploads files to before they're moved the web directory. By default Windows uses C:\Windows\Temp and in my case the permissions set on the file were kept when they were moved from Temp to the web directory. I didn't want to set IIS_IUSR permissions on this folder, so I created a different directory right under the C drive and gave it IIS_IUSR read/execute perms. Then I updated my php.ini file to point to this new directory. All's working well now. I think the key was to put this temporary directory outside of Inetpub because I tried this same set up but with the temp directory within Inetpub and it didn't work.

Folder permissions

How do I grant access to on an NTFS folder (Win2003) such that when files are added to this folder, they get the same access permissions? My problem is that I have granted read access to the 'network service' on a specific folder but when I add files to that folder (programatically generate the files to this folder), the network service does not have read access to these files. I would have thought that the permissions cascade to the files in the folder? Any help is highly appreciated.
Are the child objects in the folder inheriting permissions from the parent? Right-click the folder-properties-permissions-advanced.
And are you moving (as opposed to copying) the files in the folder? Move files also moves their permissions.

Resources