日期:2014-05-18  浏览次数:20399 次

asp.net怎么获取相对目录呢?
比如我在根目录要链接到test/a.htm

我在Default.aspx写
 <a href="~/test/a.htm">hello</a>

运行后链接却指向了
http://localhost:3352/WebSite2/~/test/a.htm

链接错了




------解决方案--------------------
<a href="<%=Page.ResolveUrl("~")%>test/a.htm">hello</a>
------解决方案--------------------
~/只能使用在服务器控件和服务器端。你不能使用在html中的

参见
http://dotnet.aspx.cc/file/Getting-Website-absolute-path-in-asp.net.aspx
------解决方案--------------------
<a href="~/test/a.htm" runat="server" >hello</a>