Image1.ImageUrl从不同的目录中检索时不呈现图像 [英] Image1.ImageUrl not rendering image when retrieving from different Directory

查看:96
本文介绍了Image1.ImageUrl从不同的目录中检索时不呈现图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述




我正在工作门户网站上工作。我有一张组织图片,我必须保存&检索。我的图像保存代码工作正常。但是我把图像倾倒在D盘中。现在,当我使用

展开 | 选择 < span class =codeDivider> | Wrap | 行号

解决方案

您是否尝试修复DirectoryPath的拼写?也许你只是去一个不存在的文件夹?


你真的有一个名为DirectoryPath的文件夹吗?这听起来像一个应该插入到字符串中以形成完整路径的变量。


假设网站的查看者没有D是否合理:用你的照片开车?



您是否尝试修复''DirectoryPath'的拼写?也许你只是去一个不存在的文件夹?



我在这里用的是目录路径只是我在这里使用的虚拟名称。


你真的有一个名为DirectoryPath的文件夹吗?这听起来像一个应该插入到字符串中以形成完整路径的变量。


假设网站的查看者没有D是否合理:开着你的照片?



不是它只是一个示例(虚拟)名称来显示我希望打开的任何类型的目录它很容易打开并且所有路径都正确地存储在我的数据库。我使用我的数据库中的路径从给定驱动器的该目录中检索jpgs ..


我的目的实际上是将jpgs保存在磁盘上的任何位置(现在,以后根据需要会有一些变化)它只是将路径存储在数据库中,当你想要检索图像时,它只是从数据库中获取路径,然后用作下面的代码行,没有问题在我已经多次调试程序的路径中。

展开 | 选择 | Wrap | 行号


< blockquote>这个不起作用的原因是因为图像位于Web服务器无法访问的目录中。因此,如果图像控件试图从服务器检索图像,它就无法实现。


这个问题有几个解决方案。

第一种是将图像移动到Web服务器上的临时图像文件夹中(例如在网站上),以便浏览器可以下载它。


第二个是实现一个ASPX页面,它检索图像(作为流)并将其写入Response.OutputStream。


此ASPX页面不会返回HTML,这是默认返回的内容,并且是Web浏览器所期望的。您需要将Response.ContentType更改为image / jpg;向浏览器表明您正在发送图像。


此页面中没有asp代码...它只是检索的纯服务器端.NET代码图像(可能基于调用页面时提供的参数)并将该图像写入流中。


例如,ASPX页面中的所有内容都将是返回完整大小的图像(VB.NET代码):

展开 | 选择 | Wrap | 行号


Hi,

I am working on a job portal. I have an Organization picture that I have to Save & Retrieve . My image saving code is working perfectly. But I am dumping the images in my D drive. Now when I use

Expand|Select|Wrap|Line Numbers

解决方案

Have you tried fixing the spelling of ''DirectoryPath''? Maybe you are just going to a folder that doen''t exist?

Do you really have a folder named "DirectoryPath"? This sounds like a variable that should have been inserted into a string to make the full path.

Is it reasonable to assume that the viewer of the site doesn''t have a D: drive with your photo?


Have you tried fixing the spelling of ''DirectoryPath''? Maybe you are just going to a folder that doen''t exist?

What I use here the word " Directory Path" is just a dummy name I am using here.

Do you really have a folder named "DirectoryPath"? This sounds like a variable that should have been inserted into a string to make the full path.

Is it reasonable to assume that the viewer of the site doesn''t have a D: drive with your photo?

No it was just an example (Dummy) name to show that any kind of directory that I wish to open It opens easily and all the paths are stored properly in my database. I use the paths from my DB to retrieve the jpgs from that directory of the given drive ..

My aim is actually to save the jpgs anywhere on the disk (for right now, later there will be some changes according to the needs) and it simply will store the path in the Database and when you want to retrieve an image, it simply takes the path from the database and then use as the following code line and there are no issue''s in the path I have debugged my program several times.

Expand|Select|Wrap|Line Numbers


The reason this isn''t working is because the image is in a directory that the web server doesn''t have access to. So if the image control tries to retrieve the image from the server it wont be able to.

There''s a couple of solutions to this problem.
The first is to move the image into a temporary images folder that is on the web server (say in the website) so that the browser can download it.

The second is to implement an ASPX page that retrieves the image (as a stream) and writes it to the Response.OutputStream.

This ASPX page will not return HTML which is what is returned by default..and is expected by the web browser. You need to change the Response.ContentType to "image/jpg" to indicate to the browser that you are sending an image instead.

There is no asp code in this page...it''s just pure server-side .NET code that retrieves the image (probably based on a parameter that is provided when the page is called) and writes that image to the stream.

For example, all that would be in your ASPX page would be the following to return the full size image (VB.NET code):

Expand|Select|Wrap|Line Numbers


这篇关于Image1.ImageUrl从不同的目录中检索时不呈现图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆