One of the most useful, but also one of the more poorly documented features of Asp.net is the Tilde (~) the tilde can be use almost anywhere in any url appears on the server control. The tilde is automatically translated to the equivalent of HttpRuntime.AppDomainAppVirtualPath (or Request.ApplicationPath). This give you the path to access your application files from its base, this is really helpful for being able to install anywhere without troubles. It also works on most configuration files in asp.net and when using Server.MapPath. In fact most of the asp.net API that receive Url's are able to run it.
Usage:
<img id="myId" src="~/images/image1.jpg" runat="server"/>
turns into:
<img id="myClientId" src="/ApplicationPath/images/images.jpg"/>
the runat attribute is important since otherwise the path won't be processed by the server.
Be the first to rate this post
- Currently 0/5 Stars.
- 1
- 2
- 3
- 4
- 5