简体   繁体   English

无法在后面的代码上设置图像

[英]cannot set image on code behind

I´m creating a result pool, where depending on the query string, the page loads the image. 我正在创建一个结果池,根据查询字符串,页面将在其中加载图像。 I have the following object 我有以下对象

<li class="labelForm"><asp:Image ID="imgImagen" runat="server" /></li>

on the page_load event i got: 在page_load事件中,我得到了:

string path = res == "OK" ? (Server.MapPath("~/Images/Results/OK/")) : (Server.MapPath("~/Images/Results/NO/"));

path = App_Code.FilePicker.FilePicker(path);
imgImagen.ImageUrl = path;

The image route is a valid one. 图片路径是有效路径。 I tested it on the browser and the explorer 我在浏览器和资源管理器上对其进行了测试

D:\\Proyectos Web Forms\\MyPage\\MyPage\\Images\\Results\\OK\\thumbsUp2.jpg D:\\ Proyectos Web窗体\\ MyPage \\ MyPage \\ Images \\ Results \\ OK \\ thumbsUp2.jpg

Since the code is running on the Page_Load event (way before render event), it shouldn't be the problem, and the file route is valid. 由于代码是在Page_Load事件上运行的(在渲染事件发生之前),所以这不应该是问题,文件路径是有效的。 However, the browser displays a little icon of empty image. 但是,浏览器会显示一个空白图像的小图标。

What could I be missing? 我可能会缺少什么?

when i add a local file to a url like that it usually converts it automaticaly for me to: from: C:/Users/Carlos/Desktop/options.gif to file:///C:/Users/Carlos/Desktop/options.gif 当我将本地文件添加到类似的url时,它通常自动将其转换为:从:C:/Users/Carlos/Desktop/options.gif到file:/// C:/ Users / Carlos / Desktop / options .gif

what happens if you take the rendered path (from the "view source") and paste it directly into explorer? 如果采用渲染的路径(来自“查看源”)并将其直接粘贴到资源管理器中会发生什么? i've seen IE9 put up a message saying it "blocked content" and i have to click "allow content" for it to work. 我已经看到IE9发出一条消息,说它“被阻止的内容”,并且我必须单击“允许内容”才能正常工作。 Maybe that's what's happening? 也许这就是正在发生的事情?

---- * edit * oh, and i also noticed you didn't specify a filename, such as helloworld.gif :) ---- *编辑*哦,我还注意到您没有指定文件名,例如helloworld.gif :)

I was using absolute routes, instead of a relative route. 我使用的是绝对路线,而不是相对路线。 Instead of this: 代替这个:
"D:\\\\Proyectos Web Forms\\\\MyPage\\\\MyPage\\\\Images\\\\Results\\\\OK\\\\thumbsUp2.jpg"

Should be this: 应该是这样的:
"~/Images/Results/OK/thumbsUp2.jpg"

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

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