在asp.net路径中使用波浪号(~) [英] use of tilde (~) in asp.net path

查看:33
本文介绍了在asp.net路径中使用波浪号(~)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个 asp.net 应用程序,以下链接在 IE 中有效,但在 FF 中无效.

i'm working on an asp.net app, the following link works in IE but not in FF.

<a href="~/BusinessOrderInfo/page.aspx" >

波浪号不是只能在asp.net 服务器控件中使用的东西吗?它将在哪里被实际路径替换?

Isn't the tilde something that can only be used in asp.net server controls. Where it will be replaced by an actual path?

是否可以在锚标记中使用波浪号?如果是,那是什么意思?

Is it possible to use the tilde in an anchor tag? If so what does it mean?

当我在根时,链接有效

www.myserver.com/default.aspx, click the link, ok!

www.myserver.com/otherpart/default.aspx, click the link, not ok!

ASP.NET 生成的链接为:

The link generated by ASP.NET is:

www.myserver.com/otherpart/~BusinessOrderInfo/page.aspx

这是故意的吗?

推荐答案

你说得对,它只适用于服务器控件.您有以下基本选项:

You are correct, it only works in server controls. You've got these basic options:

更改为 HyperLink 以作为 网络控制:

<asp:HyperLink NavigateUrl="~/BusinessOrderInfo/page.aspx" Text="Whatever" runat="server" />

或者,在服务器端运行锚作为 HTML 控件:

Or, run the anchor on the server side as an HTML Control:

<a href="~/BusinessOrderInfo/page.aspx" runat="server" >

或者,使用 Page.ResolveUrl:

<a href="<%= Page.ResolveUrl("~/BusinessOrderInfo/page.aspx") %>">...</a>

这篇关于在asp.net路径中使用波浪号(~)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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