图片网址正确但图片未显示

时间:2021-07-06 00:23:35

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

我在GoDaddy上有一个网站。正确设置了所有权限,并且图像已存在。但是,当页面加载所选项目的图像时不显示。这是我的代码

        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

spaimage是一个ASP控件和图像设置为thr的URL是D:\ hosting \ xxxxxxx \ calspas \ spaimages \ modelname.png

What am I doing wrong.

我究竟做错了什么。

2 个解决方案

#1


14  

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.

文件路径D:\ hosting \ xxxxxxx \ calspas \ spaimages \ modelname.png是图像驻留在Web服务器上的文件夹。您将此作为图片网址正确但图片未显示标记的src属性发送,该属性告诉浏览器“在D:\ hosting \ xxxxxxx \ calspas \ spaimages \ modelname.png中获取图像”。浏览器无法转到Web服务器的D驱动器,因此它在自己的D驱动器上查找该文件夹和图像。

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:

你的意思是让图片网址正确但图片未显示标签的src属性成为网站上文件夹的路径。你只是在那里 - 只需在将图像路径分配给ImageUrl属性时删除Server.MapPath部分。也就是说,而不是:

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

Do:

this.spaimage.ImageUrl = imagepath;

See if that works.

看看是否有效。

Thanks

#2


2  

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.

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

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

另外,添加一个else块

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

like

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

For debugging purposes.

用于调试目的。

#1


14  

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.

文件路径D:\ hosting \ xxxxxxx \ calspas \ spaimages \ modelname.png是图像驻留在Web服务器上的文件夹。您将此作为图片网址正确但图片未显示标记的src属性发送,该属性告诉浏览器“在D:\ hosting \ xxxxxxx \ calspas \ spaimages \ modelname.png中获取图像”。浏览器无法转到Web服务器的D驱动器,因此它在自己的D驱动器上查找该文件夹和图像。

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:

你的意思是让图片网址正确但图片未显示标签的src属性成为网站上文件夹的路径。你只是在那里 - 只需在将图像路径分配给ImageUrl属性时删除Server.MapPath部分。也就是说,而不是:

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

Do:

this.spaimage.ImageUrl = imagepath;

See if that works.

看看是否有效。

Thanks

#2


2  

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.

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

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

另外,添加一个else块

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

like

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

For debugging purposes.

用于调试目的。