locked
How to have multiple websites writting files to a single centralized folder RRS feed

  • Question

  • User1738843376 posted

    Hi,

    I need to multiple iis applications upload to a single folder that is placed outside of any of the applications scope, although in the same server.

    IIS Example:

    DefaultWebsite > Website1 (http://localhost/Website1)

    DefaultWebsite > Website2 (http://localhost/Website2)

    DefaultWebsite > Website2 (http://localhost/Website3)

    DefaultWebsite > Uploads (http://localhost/Uploads)

    I basically want Websites 1, 2 and 3 to be able to read/write files to the Uploads application.

    The goal is to have 3 distinct applications use the same image/files folder, in order to have a backoffice on each application that allows users to manage the shared files from all 3.

    Is this feasable? IF so, can someone point me in the right direction?

    Thanks

    Monday, September 30, 2019 12:30 PM

Answers

  • User475983607 posted

    Hi mgebhard,

    Thx for the reply, but i believe you got the ideia the other way around... i want the multiple websites to write files to a 4th one that is outside the scope of any of the 3. Reading from them is not the issue, although i'll be doing it also, but for that i can simply expose the files via their direct url. 
    The main issue is how to get website 1, and website 2, and also website 3 to write files to website 4 (Uploads (http://localhost/Uploads))

    .

    No, I understand the scenario. 

    Reading/writing is handled by the System.IO namespace given the sites are all on the same server.  The web applications need to two things.  1) The physical path to the Uploads directory which can be stored in configuration or a DB table.  2) Granted security access to R/W files to the directory.

    The file interface for the applications changes little.   File uploads are saved in the designated /Uploads folder.  I recommend downloading files using an ashx with System.IO.  This makes the process reusable and bit easier to maintain but you can do the same with a web page.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, September 30, 2019 6:03 PM
  • User753101303 posted

    Hi,

    All 3 sites will write uploaded files to the same physical location which could be even a network path. Usually this location is used as well to serve back files through those 3 sites rather than through a 4th dedicated web site. The account under which those sites are running will need read/write permission to this particular location.

    If using SQL Server you could also consider using https://docs.microsoft.com/en-us/sql/relational-databases/blob/filestream-sql-server?view=sql-server-2017 which does basically at the db engine level what was done "by hand" previously ie storing a "link" in the db and keeping apart the actual file content.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, September 30, 2019 6:51 PM

All replies

  • User475983607 posted

    Grant read/write access to Websites 1, 2, and 3 for the target folder that has the files.  Use the standard Systme.IO namespace to read write files.  Expose the files though a handler (ashx) or web page in each of the web sites.  Serving files outside the hosted application is a common scenario.  Below are a few ideas.

    https://www.mikesdotnetting.com/article/122/simple-file-download-protection-with-asp-net

    https://www.dotnetperls.com/ashx

    Monday, September 30, 2019 1:50 PM
  • User1738843376 posted

    Hi mgebhard,

    Thx for the reply, but i believe you got the ideia the other way around... i want the multiple websites to write files to a 4th one that is outside the scope of any of the 3. Reading from them is not the issue, although i'll be doing it also, but for that i can simply expose the files via their direct url. 
    The main issue is how to get website 1, and website 2, and also website 3 to write files to website 4 (Uploads (http://localhost/Uploads))

    .

    Monday, September 30, 2019 2:15 PM
  • User475983607 posted

    Hi mgebhard,

    Thx for the reply, but i believe you got the ideia the other way around... i want the multiple websites to write files to a 4th one that is outside the scope of any of the 3. Reading from them is not the issue, although i'll be doing it also, but for that i can simply expose the files via their direct url. 
    The main issue is how to get website 1, and website 2, and also website 3 to write files to website 4 (Uploads (http://localhost/Uploads))

    .

    No, I understand the scenario. 

    Reading/writing is handled by the System.IO namespace given the sites are all on the same server.  The web applications need to two things.  1) The physical path to the Uploads directory which can be stored in configuration or a DB table.  2) Granted security access to R/W files to the directory.

    The file interface for the applications changes little.   File uploads are saved in the designated /Uploads folder.  I recommend downloading files using an ashx with System.IO.  This makes the process reusable and bit easier to maintain but you can do the same with a web page.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, September 30, 2019 6:03 PM
  • User753101303 posted

    Hi,

    All 3 sites will write uploaded files to the same physical location which could be even a network path. Usually this location is used as well to serve back files through those 3 sites rather than through a 4th dedicated web site. The account under which those sites are running will need read/write permission to this particular location.

    If using SQL Server you could also consider using https://docs.microsoft.com/en-us/sql/relational-databases/blob/filestream-sql-server?view=sql-server-2017 which does basically at the db engine level what was done "by hand" previously ie storing a "link" in the db and keeping apart the actual file content.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, September 30, 2019 6:51 PM
  • User1738843376 posted

    Thx guys,

    I ended up using the physical path solution, which implied less changes to my base code, and i'm not very fond of storing files on the DB, even if it brings many advantages from the security and access restriction point of view, but this is not one of my requirements.

    I was previously attempting to reference the path using a relative one, and was always hitting a security wall.

    Wednesday, October 2, 2019 10:10 AM