简体   繁体   English

无法从目录中的母版页加载图像

[英]Images not loaded from master page in directory

I will make a website whit ASP.NET using C# on the background. 我将在后台使用C#创建一个使用ASP.NET的网站。 I have make my master page with the following image: 我用以下图像制作了主页:

<img src="afbeeldingen/berichten.png" alt="new messages" />

Because I have a lot of pages in my site, I have make directories in my solution. 因为我的站点中有很多页面,所以我的解决方案中包含目录。 My problem is now when I go to a page, it will not load the image. 我的问题是,当我转到页面时,它不会加载图像。 He can't find it. 他找不到。 I can edit it to ../images/message.png , but then can't he find it on the other pages outside the directory. 我可以将其编辑为../images/message.png ,但是他在目录之外的其他页面上找不到它。

图片未加载到目录中

This problem don't happens with the link -tag for load my css. 使用link -tag加载我的CSS不会发生此问题。

Important: all the images are in the master page (yellow on image below). 重要提示:所有图像都在母版页中(下图为黄色)。 The "child"-page that I will show is in a directory ( localhost:11794/wachtwoord/verloren.aspx (in english password/lost) see blue on image below). 我将显示的“子”页面位于目录中( localhost:11794/wachtwoord/verloren.aspx (使用英文密码/丢失),见下图蓝色)。

在此处输入图片说明

Can anyone help me? 谁能帮我? Thanks. 谢谢。

只需添加runat="server"和元素的ID,即可使用~引用解决方案的根

<img src="~/images/message.png" alt="new messages" runat="server" ID="myImg"/>

@Brendan Hannemann show me a link that where is expaint. @Brendan显示Hannemann的我一个链接,哪里是expaint。 The code i must use is: 我必须使用的代码是:

<img src="<%=ResolveUrl("~/afbeeldingen/berichten.png") %>" alt="nieuwe berichten" id="berichten" />

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

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