简体   繁体   English

在 web 页面中显示图像时出现问题

[英]Problem in displaying image in the web page

Trying to display an image in the webpage tried like below.尝试在网页中显示图像,如下所示。

Image1.ImageUrl = "C:\\Users\\naresh\\documents\\visual studio 2010\\Projects\\Vacancy\\Vacancy\\Files\\3\\710d7a38-5a4d-44fc-883f-5996150ba507.jpg";

Image2.ImageUrl = "C:\\Users\\naresh\\Desktop\\710d7a38-5a4d-44fc-883f-5996150ba507.jpg";

Second one Worked but first one didn't.第二个有效,但第一个没有。 I think the problem is with the spaces in the path.我认为问题在于路径中的空格。 How can I resolve this problem?我该如何解决这个问题?

Why do you not use a relative path to the location of your site?为什么不使用指向站点位置的相对路径? The path will be shorter and when you will port the web site on production server the image will still work (if the image is port to the server)路径会更短,当您将 web 站点移植到生产服务器上时,图像仍然可以工作(如果图像是服务器的端口)

May be with the Vacancy which you have given two times.可能是你给了两次的Vacancy Check it, if its the mistake.检查它,如果它的错误。

You can try to replace the spaces with %20 .您可以尝试用%20替换空格。

But I wonder if that's the problem because the image is located at your local disk.但我想知道这是否是问题所在,因为该图像位于您的本地磁盘上。 Is this webpage only running on your local machine?该网页是否仅在您的本地计算机上运行? Does the image exist?图像存在吗?

Put quoted quotation marks into the string, eg:将带引号的引号放入字符串中,例如:

Image1.ImageUrl = "\"C:\\Users\\naresh\\documents\\visual studio 2010\\Projects\\Vacancy\\Vacancy\\Files\\3\\710d7a38-5a4d-44fc-883f-5996150ba507.jpg\"";

Try giving the virtual directory path (create a virtual directory for the image folder. If it is in the root itself use the http://systemName/virtualDirectoryName/ImageFolder/image1.jpg ) instead of physical path as follows:尝试提供虚拟目录路径(为图像文件夹创建一个虚拟目录。如果它在根目录中,请使用http://systemName/virtualDirectoryName/ImageFolder/image1.jpg )而不是物理路径,如下所示:

  Image1.ImageUrl=http://systemName/virtualDirectoryName/ImageFolder/image1.jpg

Hope this helps..希望这可以帮助..

You are doing anyway very bad things in there.无论如何,你在那里做着非常糟糕的事情。 You should use Server.MapPath to resolve dynamically an IIS relative path into the file system path and you should not, never ever, load an image from the user's folders.您应该使用 Server.MapPath 将 IIS 相对路径动态解析到文件系统路径中,并且永远不要从用户的文件夹中加载图像。

Put the image inside a subfolder in your web application, like for example create a folder called images at the same level where your aspx pages are.将图像放在 web 应用程序的子文件夹中,例如在您的 aspx 页面所在的同一级别创建一个名为 images 的文件夹。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM