Possible bug: HtmlAnchor HRef property is not HTML encoded

D

Dean Brettle

Hi all,

At least under ASP.NET 2.0 (don't know about 1.1), the "href" property
of an HtmlAnchor control is not HTML encoded Is this a bug or is it by
design? If it is a bug, in which version is it expected to be fixed?

FWIW, other attributes of the HtmlAnchor control are HTML encoded and
the NavigateUrl property of the HyperLink control is also HTML encoded
so the current behavior seems to be inconsistent. Here is a simple
page to demonstrate:

<%@ Page language="c#" AutoEventWireup="true"
Inherits="System.Web.UI.Page" %>
<html>
<head></head>
<body>
<a runat="server" href='http://www.google.com/search?hl=en&q=test'
href2='http://www.google.com/search?hl=en&q=test'>HtmlAnchor</a>
<asp:HyperLink runat="server"
NavigateUrl='http://www.google.com/search?hl=en&q=test'
NavigateUrl2='http://www.google.com/search?hl=en&q=test'
Text='HyperLink' />
</body>
</html>

That renders as:

<html>
<head></head>
<body>
<a href="http://www.google.com/search?hl=en&q=test"
href2="http://www.google.com/search?hl=en&amp;q=test">HtmlAnchor</a>
<a NavigateUrl2="http://www.google.com/search?hl=en&amp;q=test"
href="http://www.google.com/search?hl=en&amp;q=test">HyperLink</a>
</body>
</html>

Note that all of the ampersands *except* the one in the first "href"
attribute are HTML encoded (ie become "&amp;")


--Dean
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,756
Messages
2,569,534
Members
45,007
Latest member
OrderFitnessKetoCapsules

Latest Threads

Top