Link relative to Application root with client tag
Is there any way to link to the application root with th开发者_JAVA技巧e ~ character (or something similar) in a client tag (e.g. <link>)? I have some external stylesheets and scripts that I need to link to in a Master page, but I don't want to hardcode the path relative to the IIS site, I want to do it based on the relative application path.
Yes, use <link href="<%= ResolveUrl("~/meep/moop.css") %>" />
.
Not the prettiest of solutions, but you should only use it a couple of times during development...
Rather than invoke ResolveUrl method, you could simply include the tilde and the runat attribute as follows:
<a href="~/page.aspx" runat="server">My Link</a>
This will resolve from the root always.
精彩评论