图片 URL 正确,但图片未显示

发布于 2024-10-11 17:11:22 字数 404 浏览 9 评论 0原文

我在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

枕花眠 2024-10-18 17:11:22

文件路径 D:\hosting\xxxxxxx\calspas\spaimages\modelname.png 是图像在 Web 服务器上所在的文件夹。您将其作为 标记的 src 属性发送,该属性告诉浏览器“前往 D:\hosting\xxxxxxx\calspas 获取图像\spaimages\modelname.png。”浏览器无法转到 Web 服务器的 D 驱动器,因此它会在自己的 D 驱动器上查找该文件夹和图像。

您的意思是让 标记的 src 属性成为网站上文件夹的路径。您就在那里 - 只需在将图像路径分配给 ImageUrl 属性时删除 Server.MapPath 部分即可。也就是说,而不是:

this.spaimage.ImageUrl = Server.MapPath(imagepath);

做:

this.spaimage.ImageUrl = imagepath;

看看是否有效。

谢谢

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's src attribute, which tells the browser, "Go get the image at D:\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's src attribute be a path to a folder on the website. You're just about there - just drop the Server.MapPath part when assigning the image path to the ImageUrl property. That is, instead of:

this.spaimage.ImageUrl = Server.MapPath(imagepath);

Do:

this.spaimage.ImageUrl = imagepath;

See if that works.

Thanks

宁愿没拥抱 2024-10-18 17:11:22

通常,如果图像“不显示”(我假设正在显示 red-x-等效项以显示“损坏的图像”),我会右键单击损坏的图像,复制 URL 并在单独的浏览器窗口中打开该 URL 。

这样,当某个脚本生成图像时,我可以看到该脚本可能显示的任何错误文本。如果没有,将显示真实图像。

此外,添加一个 else 块以进行

if (File.Exists(Server.MapPath(imagepath)))

调试

else 
{ 
    Response.Write(string.Format(
        "File does not exist at '{0}'.", 
        Server.MapPath(imagepath))); 
}

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 the

if (File.Exists(Server.MapPath(imagepath)))

like

else 
{ 
    Response.Write(string.Format(
        "File does not exist at '{0}'.", 
        Server.MapPath(imagepath))); 
}

For debugging purposes.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文