There something I still do not understand about how the Content folder works in ASP.NET MVC. To make things clearer I have a few questions:
- Is the Content folder the root folder? I mean does http://localhost/ point to Content or is it something else?
- I have a file named dummyIcon.png inside Content/images/temp folder. How do I locate it from my domain layer (which is a Code Library project)?
- What is the best practice of displaying images in ASP.NET MVC? Should I store a path to the image in the database (which I personally prefer), or do I save a byte array and return it to the view?
I found the following links to be helpful within the context of the MVC web application, but I'd still appreciate some answers to the questions posted above. Thank you.
Can an ASP.NET MVC controller return an Image?
how to display image using view and controller by ASP.NET MVC
Best Answer
Anything in the root will point to the root if it is ignored by your routes:
If you have an image placed on the on the root of your project. Then, say
http:://localhost/dummy.ico"
will give you a 404, no controller found. Until you do this in yourglobal.asax.cs
:From Code if you use says
File.Open();
you need the physical path to the file. You get it like this:It is upto you here, although I would say, putting files into the database makes a lot of sense if you want everything in one place. If you need to move your app around you would just move the data base.
When it comes to file paths, please remember you don't want duplicate file names, so you will have to give each file a
GUID
and then link it up. It could make sense if you have a large number of files (or large files itself) so you're database won't grow like crazy.HTH