当 RSS Feed 中存在查询字符串时如何对自链接进行编码
我正在为我的一些页面动态生成 RSS 源。
问题在于页面的 URL 中包含用于生成内容的查询字符串。当我将此 URL 放入标记中时,不再有效
此示例代码具有相同的内容问题并且可以在此处进行验证
<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>
该问题似乎与第二个查询字符串参数有关。但是,如果我对 URL 进行完整编码,则该 URL 无效。
我正在使用 asp.net MVC 来生成页面,并使用 Request.Url
来获取当前的 feed URL。有超过 30 个可能的参数,因此使用 URL 重写来解决该问题并不是一个可行的解决方案。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
解决方案是仅对查询字符串进行编码,而不对整个 url 进行编码。这使得提要有效。
The solution was to encode only the query string and not the entire url. This made the feed valid.