OzB
OzB

Reputation: 2221

Display image stored in different hard drive

I'm developing ASP.NET MVC website which has some articles. Each user can create as many articles as he/she wish - and there's no problem at all. I gave the users the ability to upload images related to that article (up to N images) and there's no problem with it.

My problem is that since the site will contains many images, I wish to partial the images storage to few hard drives. I have dedicated server with two hard drives, and I wish to be able to save the images in D:\ instead of the local C:\ folder. In addition, as it seems, I'll need to add another server for the site, so I wish to be able to store images on different servers which can be accessed by the same web application.

My code now is very simple: I just use Server.MapPath("~/Content/uploads/" + article.ArticleIdentifier) as the folder container and then store the related images.

What is the recommended way to share stored images in few HD or servers with the same web application?

Upvotes: 0

Views: 1653

Answers (1)

Inari
Inari

Reputation: 554

The safest way would be to create in IIS a virtual directory where the files are stored. The virtual directory can point to any location (Physical, UNC, etc) that IIS supports, so you have the most flexibility, and as far as security concerns are for uploading and managing the files, even if the files are on another server, you won't run into application permission elevation issues - you will still need to make sure that the appropriate users have read/write permissions.

Creating Virtual Directory in IIS

Accessing the virtual directories in c#:

Deprecated API: Server.MapPath("~/VirtualDir/");

Current API: HostingEnvironment.MapPath("~/VirtualDir/");

Upvotes: 1

Related Questions