Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Confused by Use of ~ in ASP.NET

Tags:

asp.net

I am programming for the first time in ASP.NET. It's proven to be very easy and I'm really enjoying it. One feature I like is that, within a web page, I can reference files from root by using the tilde (~) character and then the rest of the path. However, this does not seem to be consistent. For example, it works within the context of href, e.g.

<link href="~/css/StyleSheet.css" />

It doesn't work with respect to src, e.g.

<img src="~/images/header.jpg" />

Why is this? Is there something I'm doing wrong. The inconsistency is annoying.

like image 720
JasCav Avatar asked Dec 29 '22 03:12

JasCav


1 Answers

From my experience the ~ trick only works in server controls. If your img has runat="server" that should fix it.

like image 59
Broam Avatar answered Dec 31 '22 17:12

Broam