How to connect users to their folders in ASP.NET?

When userA uploads a file, its files will be downloaded to folder A, when userB, to folder B, etc. Roles / profiles in ASP.NET. Folders will already exist. Is anyone

+4
source share
4 answers

You probably want to put this together. There is nothing in ASP.NET to manage user files. However, the code for this should be relatively simple. Assuming the username is unique and never changes, you can combine the username with an empty one (use Path.Combine) and load it into this place. I would also block this place so that no one else could access it.

+5
source

The way I did this in the past is to use the base folder for downloading (for example, upload), and create a folder in this folder using the user ID from the database. Thus, the structure will be ... \ uploads \ 145 for the user with user ID 145.

The first thing my code does is to check if the folder exists, and if not, it calls the directories () (or whatever the syntax) to create the folder before loading it.

Additional information that may be useful to you: I also rename the file using the GUID, which avoids name conflicts if they upload 2 files with the same name. The downside is that you usually need to maintain a table with the original file name and physical (GUID) file name.

+3
source

You can simply check for a folder and create it for the user if it does not exist, but there are security implications for this. You can also try to save the data in a database and bind it to the user. It depends on what you allow users to download, I think.

0
source

There are several ways to do this:

Using forms authentication

If you use forms authentication, you can establish an agreement in which the user name or identifier can serve as the basis for the path on your server where the user can upload the file. Please note that your user will not have direct access to this folder: the user must be able to download files from your server through a web application.

Using Windows Authentication

If you use Windows authentication (for example, ActiveDirectory), you can give the user access to both the physical location of the folder and through the web application.

PS - Glad to see you here Marlon!

0
source

Source: https://habr.com/ru/post/1277102/


All Articles