如果Url来自Asp.net中的临时文件夹,则不显示图像 [英] Image not displaying if Url is from temp folder in Asp.net

查看:92
本文介绍了如果Url来自Asp.net中的临时文件夹,则不显示图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我从数据库中以byteArray格式获取Image的内容,并在Asp.net中显示内容图像标记。这里的问题是当我将图像文件保存在我的工作文件夹中的特定位置并显示图像正常工作时。



但是如果我试图暂时保存图像文件夹并将临时文件夹url提供给图像标记它没有显示图像。代码是:



I am taking the content of Image in byteArray format from database and displaying the Content image tag in Asp.net. Here the problem is when i save the image file in Specific location in my working folder and displaying the image working fine.

But if i trying to save the image in temporary folder and giving the temporary folder url to image tag it doesn''t displaying the image. The code is:

 Bitmap bi = new Bitmap(byteArrayToImage(FileUpload1.FileBytes));

 //This code working fine

 string path = Server.MapPath("Images/") + FileUpload1.PostedFile.FileName;
         bi.Save(path , ImageFormat.Jpeg);
        Image1.ImageUrl = "Images/" + FileUpload1.PostedFile.FileName;



//This code didn't displaying the image.

         bi.Save(Path.GetTempPath() + FileUpload1.PostedFile.FileName, ImageFormat.Jpeg);
        Image1.ImageUrl = Path.GetTempPath() + FileUpload1.PostedFile.FileName;



这里的tempFolder有什么问题。我正在使用Windows7操作系统。在这里我使用temparory文件夹自动删除文件夹中创建的图像。

请在这里给出有用的技巧。



谢谢


what is the problem with the tempFolder here.I am using the Windows7 operating system. Here i am using the temparory folder for automatically deleting the created images in folder.
Please give to useful technique here.

Thank you

推荐答案

糟糕的设计。

将您的应用程序想象为在Web服务器上运行(实际上,开发服务器是一个简单的Web服务器)。 Web服务器是否会从它的OS临时文件夹中提供服务?从不。

您只能使用Web服务器服务范围内的图像源。请注意,浏览需要逻辑服务路径,而不是物理路径 - 因为它无法访问服务器物理文件系统。
Bad design.
Think of your application as running on a web server (actually the development server is a simple web server). Will the web server serve from it''s OS temporary folder? Never.
You can only use image sources that are in the served scope of your web server. And be aware, that the browses needs logical served paths, not physical ones - since it can not access server physical file system.


这篇关于如果Url来自Asp.net中的临时文件夹,则不显示图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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