How to protect a directory in asp.net MVC?

What would be the easiest way to secure a directory in asp.net mvc?

I currently have a folder of files that are owned by numerous users of the site. Ideally, I don't want one user to be able to enter the URL of one of these documents in a browser and be able to access it. These files should only be loaded through a controller action that allows the download by validating the user credentials and then returning the file.

Thanks in Advance

+2


source to share


2 answers


My solution for them usually is that this directory exists outside of network access. For example, instead of storing them in the c: \ inetpub \ wwwroot \ docs directory, just save them in the C: \ inetpub \ docs folder.

Just make sure your controller reads /? wrote? privilege.



This created a better solution for me when I was adding / removing folders as my host limited my ability to turn off the file monitor. And it turns out that deleting the application subfolder results in reworking> application pool> _ <

+2


source


Store files in application data and check for controller action in FileResult. Thus, the files are never directly displayed.



+7


source







All Articles