是增加RUNAT ="服务器" HTML标记来获得相对路径在ASP.net一个优雅的解决方案吗? [英] Is Adding runat="server" to HTML tags to get relative path in ASP.net an elegant solution?

查看:98
本文介绍了是增加RUNAT ="服务器" HTML标记来获得相对路径在ASP.net一个优雅的解决方案吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一对夫妇,我用我的新网站的不同位置ASP.Net用户控件的。这些用户控件有像这样的链接:

I've got a couple of ASP.Net Usercontrols that I am using in different locations of my new website. These usercontrols had links like this :

<a href="daily/panchang/"></a>

如果该用户控件在各个子目录中的相对路径是行不通的页面中,我不想在路径提供了我的全部的网站名称。所以,我没有这个

If the usercontrol is used in pages in various subdirectories the relative path just doesn't work, and I don't want to provide my full website name in the path. So I did this

<a href="~/daily/panchang/" runat="server">

和现在的ASP.Net'〜'标记正常工作,以解决根路径。

and now the ASP.Net '~' marker works correctly to resolve the root path.

什么情况下可以纪念在那里我有需要解决与=服务器的根本路径,或者你知道更好,HTML的方式?我所有的HTML标签

Is it okay to mark all my HTML tags where I have the need to resolve the root path with runat="server" or do you know of a better, HTML way?

感谢

推荐答案

我不会说是否这是一个完美的解决方案,我只想指出的System.Web内alterantive:

I won't say whether it's an elegant solution, I'll just point out an alterantive within System.Web:

<a href="<%= VirtualPathUtility.ToAbsolute("~/daily/panchang/") %>">

这篇关于是增加RUNAT =&QUOT;服务器&QUOT; HTML标记来获得相对路径在ASP.net一个优雅的解决方案吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆