开发者

Link relative to Application root with client tag

开发者 https://www.devze.com 2023-03-28 13:58 出处:网络
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 nee

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消