Search code examples
c#asp.net-coredirectorydata-protection

Accessing protected directories with ASP.net core application


I would like to create a password protected directory on the remote webserver and have my webapp access that folder as a ‘user’ and be able to read and write. I assume I need a method that can include a username/password for that specific directory?

Is there a recommended way to do that?

I have looked at the ‘DirectoryInfo’ and ‘FileInfo’ methods, but I cannot find anything on this subject. I have looked at several threads about WnetAddConnection2, but I cannot make heads or tails out of these suggestions, as they focus on creating a Share in Windows, more than just allowing access. I am looking for something in near code as: saveFile (name=xyz) to directoryPath(name, accessCredentials)

I run my ASP.NET Core 2.2 Web Application on a externally hosted environment. One of the features of the app is to upload documents to a directory (folder).

The current setup of my hosting provider allows anonymous to access those documents through a browser (e.g. (www.mydomain.com/securedocs/thisdoc.txt). The hostingprovider does allow for a password-protected directory. I have created such a directory.

EDIT: The directories are located under HttpDocs/wwwroot/ on a webserver, hosted by an external hostingprovider.


Solution

  • You can change directory permission in Windows.

    You can set with which user your application will run in IIS.

    So you don't have to care about username and password in your application, just ensure the user that IIS run your application, is able to read and write to this folder.