views:

1177

answers:

4

I have a scenario where I need to upload a file from one web application and use it in another one. My setup is the following.

  • One server, hosting two web applications in IIS - both are ASP.NET
  • One of the applications is used to administer the other one + a bunch more stuff
  • I need to upload a file from this admin app, save the path in DB through the DAL and then access the file from the other web app, which would provide the file for download
  • I keep files on disk, only the path in DB

So where and how can I upload the file so that it can be accessed from both web applications? Should I use a service or is there some other way?
Here are some related questions I found, but I don't think they cover my particular scenario:
http://stackoverflow.com/questions/63146/how-to-handle-file-uploads-to-a-dedicated-image-server
http://stackoverflow.com/questions/51256/how-to-upload-a-file-to-a-wcf-service

A: 

Can I ask why you are not keeping the file in the DB? This would make passing it around much easier.

MBoy
Because the DB would get bloated, and sometimes this is not acceptable. But this is another discussion with a lot of debate around it.
Slavo
+2  A: 

You could setup a new virtual directory in each application that points to the same folder on your server where you would upload the files to. Lets say you created a new folder on your c: drive called "uploads" i.e. c:\uploads. Then in IIS setup a new virtual directory called "uploads" that points to c:\uploads for each web application. That should give both sites access to the files.

Erikk Ross
A: 

Assuming the file path you put in the DB is accessible from the non-admin web app (which it sounds like it is), the file just needs to go somewhere that both applications have access rights to. Only the admin app would need to have write access.

You can configure what user account an IIS web site will run under Website properties > Directory Security in the IIS management console. Then just make sure to set appropriate directory permissions.

roryf
+3  A: 

Since both applications are on the same server this should be straightforward:

  • Save the uploaded file somewhere on the server.
  • Create a virtual directory in any application needing to expose the files pointing to the physical path.
  • Save the virtual path in the db for flexibility
HectorMac