如何在asp.net中使用超链接


你好,我是 ASP.NET 技术新手

我需要一些小信息,我使用“文件系统”作为我在 C#.net Web 应用程序中的主机,

这里我的问题是我通过超链接将网址导航到“www.google.com”,但我认为更像是

http://localhost:1162/Secure%20Distributed%20Systems/www.google.com

我的示例代码是

HyperLink1.NavigateUrl ="www.google.com";

我也在尝试像
超链接==>
属性==>
导航url =“WWW.google.com”

我正在尝试这两种类型,问题是什么,如何避免这种情况

解决方案1

尝试这个

<asp:HyperLink ID="MyHyperLinkControl" NavigateUrl="http://google.com" runat="server">link</asp:HyperLink>

解决方案89

您的 ASP.NET 超链接代码将被转换为:

超文本标记语言
<a href="www.google.com">link</a>

如果任何链接的前缀不是符号斜杠“https://www.codeproject.com/”或方案“https/http”,浏览器将在您提供的链接后附加当前的 Web 文件夹路径。

例如,这个:

超文本标记语言
www.google.com

会变成这样:

超文本标记语言
Fastest Web Hosting Services | Buy High Quality Hosting
Monsterhost provides fast, reliable, affordable and high-quality website hosting services. We're a Hosting Monster with unmatched security, 24/7 expert support.

或这个:

超文本标记语言
Fastest Web Hosting Services | Buy High Quality Hosting
Monsterhost provides fast, reliable, affordable and high-quality website hosting services. We're a Hosting Monster with unmatched security, 24/7 expert support.

它与 ASP.NET 中的 Hyperlink 服务器控件无关。 这是 HTML 的默认行为。

因此,您必须在其前面加上该方案的前缀:

超文本标记语言
https

像这样:

网络平台
<asp:HyperLink ID="hp1" runat="server" NavigateUrl="https://www.google.com">Link</asp:HyperLink>

解决方案2

使用

它肯定会起作用

hyperlink1.NavigateUrl="http://www.google.com"  

コメント

タイトルとURLをコピーしました