Images that are in App_Data folder not shown in browser

六月ゝ 毕业季﹏ 提交于 2019-11-27 13:56:34
marc_s

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.

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.

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!

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!!!

It depends! ;)

There are good reasons for saving images in App_Data. In situations where your users can upload their files or logos it will protect these files and not make them accessible to other users or being public.

Most important, it's the only way having different files per server/deployment instance.

When deploying your app you can protect these files uploaded by users per server instance by enabling "Exclude files from App_Data" in your deployment configuration.

If you want to access these files by url use a download handler, downloadfile.ashx for instance.

Hope this helps.

Chaturvedi Dewashish

Contents from App_Data folder can be served but not directly.
Direct access is not possible and indirect is not recommended. It is intentional.

however adding a virtual path can do this. See this question


I think top three answer serves your purpose.
Store images in resource folder either global or local these are also special folders and contents can be accessed programaticaly.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!