Sorry in advance for the long question. I'm really interested in programmatically checking if the Windows executable identifier matches the appropriate Windows privileges for writing to a directory (or file) in an ASP.NET web services application. But I agree to obtain effective delete (change) rights for the user for this directory or file. The problem is that I would like to be able to do this without typing temporary files or not necessarily performing an IO action and handling the exception.
Yes, there is a question about this already (see How can I programmatically determine if I have write permissions using C # in .Net? ) I usually agree with the accepted answer that the best method is to simply try the IO action and handle any exceptions - System.IO methods really throw a System.UnauthorizedAccessException to indicate a failure as a result of a privilege failure. But in the case of UPLOADING files, I would really like to check the privileges before spending time and resources on downloading data, since only AFTER the download, we can try to write the corresponding file or folder. I regret that any users upload a 2 GB file via http only after it is established after the download is complete that they do not have permission to upload the file to the destination.
The usual approach to testing write access, if you do not want to do the actual recording, is to write a temporary file. There is an answer to another question indicating this. This is what our code is currently doing. BUT window protection provides write access without deletion privileges. Users who have ONLY write access, but without deletion, leave all kinds of restored .tmp files. And no, we donโt want to use a domain administrator account to reset the ACL in tmp files, and then delete them. The approach I took was to check if the user has write permissions using System.IO.Directory.GetAccessControl (..) or System.IO.File.GetAccessControl (..) and deals with various access rules and ACE returns ... but with this I still have problems with EFFECTIVE privileges, that is, in most cases I also need to look for user membership in any of the groups listed in ACE that have object permissions. There should be an easier way ... doesnโt exist?
source share