A client of mine was having issues while using an image control within a master page. This master page was reference by content pages at a number of different sub directory levels within the application. The browser was unable to resolve or display images located off of the application root when the ulr contained a tilde (~) at the beginning of the path.
<img src="~/Image/AndrewPix.jpg" />
The tilde (~) is a shortcut to the HttpRuntime.AppDomainAppVirtualPath which will normally resolve back to the root of the virtual directory but this shortcut will only be resolved within server side controls. The standard HTML image control (img) is not rendered at the server and will simply pass the tilde on to the client browser. The issue was related to this and not directly to the use of master pages.
The solution is to insure that the control is rendered at the server. This can be done by adding the runat="server" property to the standard HTML image control or by using the ASP.NET image control.
<img src="~/Image/AndrewPix.jpg" runat="server" />
<asp:Image runat="server" ImageUrl="~/Image/AndrewPix.jpg" />
Remember Me
a@href@title, strike
Powered by: newtelligence dasBlog 2.0.7226.0
Disclaimer The opinions expressed herein are my own personal opinions and do not represent my employer's view in any way.
© Copyright 2008, Andrew Robinson
E-mail