Possible bug: HtmlAnchor HRef property is not HTML encoded

Discussion in 'ASP .Net Web Controls' started by Dean Brettle, Dec 28, 2005.

  1. Dean Brettle

    Dean Brettle Guest

    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
     
    Dean Brettle, Dec 28, 2005
    #1
    1. Advertisements

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 (here). After that, you can post your question and our members will help you out.