Link relative to application root with client tag

Is it possible to associate the root directory of the application with the ~ symbol (or something similar) in the client tag (for example, <link>)? I have some external style sheets and scripts that I need to link on the main page, but I don’t want to hardcode the path relative to the IIS site, I want to do this based on the relative path of the application.

+4
source share
2 answers

Yes, use <link href="<%= ResolveUrl("~/meep/moop.css") %>" /> .

Not the most beautiful of solutions, but you should use it only a couple of times during development ...

+9
source

Instead of calling the ResolveUrl method, you can simply include the tilde and runat attribute as follows:

<a href = "~ / page.aspx" runat = "server"> My Link </a>

This will always be resolved from the root.

0
source

All Articles