views:

644

answers:

4

When I set image URL property to asp image control that is in App_Data folder, image is showing in page design view but not in browser.

<form id="form1" runat="server">
<div>
    <asp:Image ID="Image1" runat="server" ImageUrl="~/App_Data/p3.jpg" />
</div>
</form>

It seems to be looking straight forward, but not showing image.

Thanks

+8  A: 

The App_Data folder is a special folder reserved for data such as database files and so on, and will NOT render out any contents on the web. This is by design, and intentional and cannot be changed (as far as I know).

Your images do definitely not belong into the App_Data subfolder - put them into a /images folder or something more appropriate.

Marc

marc_s
but I need to add images folder liek App_data/adver/images.jpg
Muhammad Akhtar
@Muhammad: No, you don't! :P
Cerebrus
The ASP.NET runtime will **NOT** allow you to do that. PERIOD. Move your images elsewhere, there is no other solution.
marc_s
Thanks Marc.......
Muhammad Akhtar
+5  A: 

Images should never be stored in the App_Data Folder. This is reserved for files that should never be served to the user directly, such as .mdb database files, etc.

I would create a /Resources or /Resources/Images folder off the root of the site.

Chris Ballance
Thanks Chris...
Muhammad Akhtar
A: 

Okay, time to do the impossible... While you cannot load images directly from the app_data folder, you can write your own http handler which will read the image file from the app_data folder and send it back to the client. It would be a work-around but in general, the data is meant for data that only your application can read. By having a handler reading the data, you can still return those images.

But it's bad practice and if you'd be working for me, you'd be fired immediately!!!

Workshop Alex
Even thinking through how to circumvent asp.net to allow images to be served from app_data is a bad idea...
Chris Ballance
Thanks for sharing an Idea.
Muhammad Akhtar
@Chris, I agree! I'll fire myself! ;-)
Workshop Alex
A: 

I disagree. When hiding images in the App_Data folder and creating your own http-handler you secure your images and can add copyright-text etc. on the images before you show them.

I do this when I have highres pictures i don't wan't everybody to get, and having the http-handler downscale the image and put on some copyrighttext. Great!

Terje