图像未在Asp.net图像控件和ImageButton中显示 [英] Image isn't showing in Asp.net Image control and ImageButton

查看:72
本文介绍了图像未在Asp.net图像控件和ImageButton中显示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

虽然URL正确,但我无法在Image或ImageButton控件中显示图像。我通过在地址栏中浏览到它来测试网址。它适用于数据uri,而不适用于位置。



我在页面加载时将图像分配给控件。这是CS代码:



Image1.ImageUrl = Server.MapPath(UserDP \\\。jpeg);



我看到的是一个空的图像控件。

Although the URL is correct, I can't show image in either Image or ImageButton control. I tested the url by browsing to it in address bar. It works with data uri and not with location.

I'm assigning image to the control in page load. Here's the CS code:

Image1.ImageUrl = Server.MapPath("UserDP\\14.jpeg");

An empty image control is all I see.

推荐答案

Server.MapPath 返回文件在服务器上的物理路径

例如: C:\inetpub \wwwroot \UserDP\14.jpeg



除非客户在中的图像完全在他们的计算机上使用相同的路径,否则将无效。

提示:当您直接浏览URL时,它会起作用,因为您在本地测试该站点。服务器和客户端是同一台计算机。)



要在Web应用程序中显示图像,您需要使用绝对路径,相对路径或应用程序相对路径。例如,假设 UserDP 文件夹位于您网站的根目录中,请使用:

Server.MapPath returns the physical path of the file on the server.
For example: C:\inetpub\wwwroot\UserDP\14.jpeg

Unless the client has an image in exactly the same path on their computer, that won't work.
(Hint: It works when you browse to the URL directly because you're testing the site locally. The server and client are the same computer.)

To display an image in a web application, you need to use either an absolute path, a relative path, or an app-relative path. For example, assuming the UserDP folder is in the root of your site, use:
Image1.ImageUrl = "~/UserDP/14.jpeg";


这篇关于图像未在Asp.net图像控件和ImageButton中显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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