开发者

Disable Url Encoding on Asp.Net HyperLink Control in Header tag

I am attempting to dynamically add a element to the html head tag in ASP.Net.

Here is my code in the master page:

    public string LinkConincal
    {
        get
        {
            return Canonical.Href;
        }
        set
        {
            Canonical.Attributes["href"] = value;
        }
    }

I use this master page property on each page and set the value to the appropriate link.

My problem is if there is a & character in the url it is being encoded (&=>&) and the link becomes invalid.

To see an example of this, on my page www.kwyps.com/topic.aspx?t=11&p=1

it is being displayed as

<link id="Canonical" rel="canonical" href="http://www.kwyps.com/topic.aspx?t=11&amp;p=1" />

instead of what I want:

<link id="Canonical" rel="canonical" href="http://www.kwyps.com/topic.aspx?t=11&p=1" />

How do I disable the Url Encoding? Or is this valid? I'm trying to do this for开发者_开发问答 SEO purposes.


It's not urlencoding its HTML/XML-encoding and is probably both valid, depending what kind of html standard you define.

If you want to force your output you can use <%=YourCanonical%> in the aspx/whatever and then set it in the code via public string YourCanonical = "http:/..."

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜