问题
I have a tag in a master page. I use this master page in many folders. So the src path of the tag should be different for each folder. Here is my code :
<img src="images/1.gif" />
and I have a folder named "images" and a folder named "Users". Master Page is in the root, but I use it in Users folder.
How can I set a dynamic address for src?
回答1:
The easiest way would be to use an asp:Image tag. You need to add runat="server" in order to use ~ syntax to resolve your URLs.
<asp:Image ID="myImage" runat="server" ImageUrl="~/images/1.gif" />
回答2:
Just use <img runat="server" src="~/images/1.gif" />
. This is documented here.
来源:https://stackoverflow.com/questions/1506408/relative-path-in-master-page-for-img-tag