简体   繁体   English

ASP.NET - 从 Web.sitemap 文件输出尖括号

[英]ASP.NET - Output of angle brackets from a Web.sitemap file

I'm using a repeater to create a table of contents.我正在使用转发器来创建目录。 The data comes from a Web.sitemap file.数据来自 Web.sitemap 文件。

One page in the site is about List<T> , so the sitemap node looks like this:站点中的一页是关于List<T> ,因此站点地图节点如下所示:

<siteMapNode url="~/path-to-page" title="List&lt;T&gt;"/>

The output for this particular node becomes:此特定节点的输出变为:

<a href="/path-to-page">List<t></t></a>

The angle brackets are turned into a nonsense HTML tag.尖括号变成了无意义的 HTML 标签。

I've tried two other character entities and neither one gets output as actual angle brackets.我已经尝试了另外两个字符实体,但没有一个将输出作为实际的尖括号。 The output is the same as above.输出与上面相同。

title="List&#60;T&#62;"
title="List&#x3C;T&#x3E;"

Before I go in and figure out some sort of string.Replace solution or something, I was wondering if I'm missing some other way of putting angle brackets in the sitemap file so they're output properly.在我进入并找出某种string.Replace解决方案或其他东西之前,我想知道我是否缺少将尖括号放入站点地图文件中的其他方法,以便它们可以正确输出。

PS the ItemTemplate just has: PS ItemTemplate 只有:

<asp:HyperLink runat="server" NavigateUrl='<%# Eval("Url") %>' Text='<%# Eval("Title") %>'>
</asp:HyperLink>

As I was stepping through the results I realized that the angle brackets were not output in a weird way but actually as angle brackets, which is why they looked like HTML and produced the nonsense <t> tag.当我逐步查看结果时,我意识到尖括号不是以一种奇怪的方式输出,而是实际上是尖括号,这就是为什么它们看起来像 HTML 并产生了无意义的<t>标签。

I just had to HtmlEncode the output:我只需要HtmlEncode输出:

<asp:HyperLink runat="server" 
    NavigateUrl='<%# Eval("Url") %>' 
    Text='<%# Server.HtmlEncode(Eval("Title").ToString()) %>'>
</asp:HyperLink>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM