图片 URL 正确,但图片未显示
我在 GoDaddy 上有一个网站。所有权限均已正确设置并且图像确实存在。但是,当页面加载时,所选项目的图像不会显示。这是我的代码
imagepath = "~/spaimages/" + currentSpaModel.Name.ToString() + ".png";
if (File.Exists(Server.MapPath(imagepath)))
{ this.spaimage.ImageUrl = Server.MapPath(imagepath); }
spaimage 是一个 ASP 控件,图像设置的 thr URL 是 D:\hosting\xxxxxxx\calspas\spaimages\modelname.png
我做错了什么。
I have a website on GoDaddy. All permissions are set correctly and the image DOES exist. However when the page loads the image for the item selected does not show. Here is my code
imagepath = "~/spaimages/" + currentSpaModel.Name.ToString() + ".png";
if (File.Exists(Server.MapPath(imagepath)))
{ this.spaimage.ImageUrl = Server.MapPath(imagepath); }
spaimage is an ASP control and thr URL that the image is set to is D:\hosting\xxxxxxx\calspas\spaimages\modelname.png
What am I doing wrong.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
文件路径 D:\hosting\xxxxxxx\calspas\spaimages\modelname.png 是图像在 Web 服务器上所在的文件夹。您将其作为
标记的
src
属性发送,该属性告诉浏览器“前往D:\hosting\xxxxxxx\calspas 获取图像\spaimages\modelname.png
。”浏览器无法转到 Web 服务器的 D 驱动器,因此它会在自己的 D 驱动器上查找该文件夹和图像。您的意思是让
标记的
src
属性成为网站上文件夹的路径。您就在那里 - 只需在将图像路径分配给ImageUrl
属性时删除Server.MapPath
部分即可。也就是说,而不是:做:
看看是否有效。
谢谢
The file path
D:\hosting\xxxxxxx\calspas\spaimages\modelname.png
is the folder where the image resides on the web server. You are sending this as the<img>
tag'ssrc
attribute, which tells the browser, "Go get the image atD:\hosting\xxxxxxx\calspas\spaimages\modelname.png
." The browser cannot go off to the D drive of the web server, so it looks on its own D drive for that folder and image.What you mean to do is to have the
<img>
tag'ssrc
attribute be a path to a folder on the website. You're just about there - just drop theServer.MapPath
part when assigning the image path to theImageUrl
property. That is, instead of:Do:
See if that works.
Thanks
通常,如果图像“不显示”(我假设正在显示 red-x-等效项以显示“损坏的图像”),我会右键单击损坏的图像,复制 URL 并在单独的浏览器窗口中打开该 URL 。
这样,当某个脚本生成图像时,我可以看到该脚本可能显示的任何错误文本。如果没有,将显示真实图像。
此外,添加一个
else
块以进行调试
。
Often, if an image "does not show" (I assume a red-x-equivalent is being displayed to show "broken image"), I right-click the broken image, copy the URL and open the URL in a separate browser window.
This way, when the image is being generated by some script, I see any error text that the script might have shown. If not, the real image would be displayed.
In addition, add an
else
block to thelike
For debugging purposes.