John
John

Reputation: 30556

How to encoding the self link when there is a querystring in an RSS Feed

I am dynamically generating an RSS Feed for some of my pages.

The issue is that the pages contain a query string in the URL to generate the content. When I place this URL into the tag is is no longer valid

This sample code has the same issue and can be validated here

<rss version="2.0"  xmlns:atom="http://www.w3.org/2005/Atom">
  <channel>
    <title>RSS Feed</title>
    <link>http://localhost/?id=1&title=sample</link>
    <atom:link href="http://localhost/?id=1&title=sample" rel="self" type="application/rss+xml" />
    <description>Sample Items for SO</description> 
    <language>en</language>
    <copyright></copyright>
    <webMaster>website@localhost (webmaster)</webMaster>
    <ttl>5</ttl>
    <item>
        <title>Page 1</title>
        <link>http://localhost/page1</link>
        <guid>http://localhost/page1</guid>
        <description></description>
        <pubDate>Tue, 25 Jan 2011 11:44:41 GMT</pubDate>
    </item>
  </channel>
</rss>

The issue seems to be with the second query string parameter. However if I encode the URL in full it is not valid.

I am using using asp.net MVC to generate the page and Request.Url to get the current feeds URL. There are over 30 possible parameters so using URL re-writing to get around the issue is not a viable solution.

Upvotes: 2

Views: 713

Answers (1)

John
John

Reputation: 30556

The solution was to encode only the query string and not the entire url. This made the feed valid.

Upvotes: 1

Related Questions