asp.net:在普通非服务器端 html 控件中引用相对于 root 的页面
我有一个深度嵌套的页面。以及位于根路径中的一个。在深层嵌套页面内部,我有一个锚标记,该标记应该导航到另一个页面(不在根目录中,但很容易指定根相对路径)。
我已完成以下尝试指定根相对路径:
Home
->这给了我一个 404 错误。它无法将 ~
部分解析为根路径。
另一种选择是向上移动一个目录:
Home
->这很头痛。
然后我尝试了这个:
Home
->这又给了我一个404。它只是删除了 localhost:
部分后面的内容,并用 /home/main.aspx
附加它。
这里指定根相对路径的方法是什么?
PS:我假设根相对路径将解析为服务器控件
I've a page that is deeply nested. And one that is in the root path. Inside of the deeply nested page I have an anchor tag which is supposed to navigate to another page (which is not in the root, but it is easy to specify a root relative path).
I've done the following trying to specify a root relative path:
<a href="~/home/main.aspx">Home</a>
-> This one gives me a 404 error. It is not able to resolve ~
part to the root path.
The other option is to travel one directory up:
<a href="../../../home/main.aspx">Home</a>
-> This is headache.
Then I tried this:
<a href="/home/main.aspx">Home</a>
-> This gave me a 404 again. It simply removed what came after the localhost:<port_number>/
part and affixed it with /home/main.aspx
.
What is the way to specify a root relative path here?
PS: I assume the root relative path will resolve for server controls
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
波形符 (~) 只能由
WebControl.ResolveUrl
方法识别,因此您必须在Page
(这是一个WebControl
)上调用此方法。代码>A tilde (~) is only recognized by the
WebControl.ResolveUrl
method, so you will have to invoke this method on thePage
, which is aWebControl
如果您使用 asp.net 超链接控件,您将能够使用“~”。如果您不想使用服务器控件,我认为您陷入困境。
“/”将通过常规链接将您带到站点的根目录,但您必须检查虚拟目录的设置方式。
If you use the asp.net hyperlink control you will be able to use the '~'. If you don't want to use a servercontrol I think your stuck.
'/' will take you to the root of the site on a regular link but you have to check how you have the virtual directory is set up.