App_Data文件夹中的图像未显示在浏览器中

时间:2022-02-23 00:26:01

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.

当我将图像URL属性设置为App_Data文件夹中的asp图像控件时,图像显示在页面设计视图中,但不显示在浏览器中。

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

It seems to be straightforward, but it's not showing the image.

它似乎很简单,但它没有显示图像。

6 个解决方案

#1


38  

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).

App_Data文件夹是为数据库文件等数据保留的特殊文件夹,不会在Web上呈现任何内容。这是设计的,有意的,不能改变(据我所知)。

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

您的图像绝对不属于App_Data子文件夹 - 将它们放入/ images文件夹或更合适的位置。

#2


8  

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.

图像不应存储在App_Data文件夹中。这是为永远不应直接提供给用户的文件保留的,例如.mdb数据库文件等。

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

我将在站点的根目录下创建/ Resources或/ Resources / Images文件夹。

#3


4  

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.

我不同意。将图像隐藏在App_Data文件夹中并创建自己的http处理程序时,可以保护图像,并可以在显示图像之前在图像上添加版权文本等。

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!

当我有高调的图片时,我这样做,我不是每个人都得到的,并且让http处理程序缩小图像并加上一些版权文本。大!

#4


3  

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.

好的,是时候做不可能了......虽然你无法直接从app_data文件夹加载图片,但你可以编写自己的http处理程序,它将从app_data文件夹中读取图像文件并将其发送回客户端。这将是一种解决方法,但一般来说,数据仅适用于您的应用程序只能读取的数据。通过让处理程序读取数据,您仍然可以返回这些图像。

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

但这是不好的做法,如果你为我工作,你会被立即解雇!

#5


0  

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

可以提供App_Data文件夹中的内容,但不能直接提供。不可能直接访问,也不建议间接访问。这是故意的。

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.

我认为前三个答案符合您的目的。将图像存储在全局或本地资源文件夹中,这些也是特殊文件夹,可以通过programaticaly访问内容。

#6


0  

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.

在App_Data中保存图像有充分的理由。在用户可以上传文件或徽标的情况下,它将保护这些文件,而不是让其他用户可以访问或公开。

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.

部署应用程序时,您可以通过在部署配置中启用“从App_Data中排除文件”来保护每个服务器实例的用户上载的这些文件。

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

如果你想通过url访问这些文件,请使用下载处理程序,例如downloadfile.ashx。

Hope this helps.

希望这可以帮助。

#1


38  

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).

App_Data文件夹是为数据库文件等数据保留的特殊文件夹,不会在Web上呈现任何内容。这是设计的,有意的,不能改变(据我所知)。

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

您的图像绝对不属于App_Data子文件夹 - 将它们放入/ images文件夹或更合适的位置。

#2


8  

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.

图像不应存储在App_Data文件夹中。这是为永远不应直接提供给用户的文件保留的,例如.mdb数据库文件等。

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

我将在站点的根目录下创建/ Resources或/ Resources / Images文件夹。

#3


4  

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.

我不同意。将图像隐藏在App_Data文件夹中并创建自己的http处理程序时,可以保护图像,并可以在显示图像之前在图像上添加版权文本等。

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!

当我有高调的图片时,我这样做,我不是每个人都得到的,并且让http处理程序缩小图像并加上一些版权文本。大!

#4


3  

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.

好的,是时候做不可能了......虽然你无法直接从app_data文件夹加载图片,但你可以编写自己的http处理程序,它将从app_data文件夹中读取图像文件并将其发送回客户端。这将是一种解决方法,但一般来说,数据仅适用于您的应用程序只能读取的数据。通过让处理程序读取数据,您仍然可以返回这些图像。

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

但这是不好的做法,如果你为我工作,你会被立即解雇!

#5


0  

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

可以提供App_Data文件夹中的内容,但不能直接提供。不可能直接访问,也不建议间接访问。这是故意的。

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.

我认为前三个答案符合您的目的。将图像存储在全局或本地资源文件夹中,这些也是特殊文件夹,可以通过programaticaly访问内容。

#6


0  

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.

在App_Data中保存图像有充分的理由。在用户可以上传文件或徽标的情况下,它将保护这些文件,而不是让其他用户可以访问或公开。

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.

部署应用程序时,您可以通过在部署配置中启用“从App_Data中排除文件”来保护每个服务器实例的用户上载的这些文件。

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

如果你想通过url访问这些文件,请使用下载处理程序,例如downloadfile.ashx。

Hope this helps.

希望这可以帮助。