views:

347

answers:

3

I am working with two different web sites in asp.net. In the first project i upload some images to a specific folder under the project root and save just the filename in the database, now i am trying to display this images at some page of the second project I know the filename from the database and the image folder as absolute pat but I have not been able to display the image, even thought when looking in firebug the image src is correct src="D:/MyFolder/image.jpg" the image does not display, probably because it is not pointing in the right directory. I have also tried using Server.MapPath and then my D location but still no success.

I am sure someone has faced the same situation before and was really hoping to get some hint to manage this. Thank you in advance

+1  A: 

I don't think you can serve files outside of your application path by default. It's called Code Access Security. You can read up on it here:
http://msdn.microsoft.com/en-us/library/930b76w0.aspx

You can fix this by changing your trust level to High in your web.config:
http://msdn.microsoft.com/en-us/library/tkscy493.aspx

I wouldn't recommend doing this for any site that is externally accessible. In fact, depending on how/where you're hosting your application, this option may be restricted.

Jim Schubert
+1  A: 

You can only "link" to files that exist relative to the same project or are hosted on another site via an absolute URL.

If you want to service files outside the application/website (on disk or in a database) you will need to build a mechanism that gets the file and binary writes it to the browser, setting the MIME type etc. This is best done using an HttpHandler.

Mark Redman
+1  A: 

I found my solution, strange but i didn't catch it before. Uploaded pictures under a project can always be accessed using the url of the project http://www.yourwebsite.com/images/photo.png now in the second project you can use reference the images using this url and concatenating the file name which i store on database. I think this is the best solution and without changing the code access security which i think can bring other problems with it. Anyway thank you guys.

Izabela
+1 for the follow-up and explanation. (also, you can mark your own answer as the solution)
Jim Schubert