尝试在谷歌搜索,但没有找到任何有用的东西来解决这个问题,所以我们在这里。有一个页面,使用 RSS 应该提醒来自 DB 的 10 条最新消息。使用本课完成了这项任务 - http://net.tutsplus.com/tutorials/asp-net/how-to-build-an-rss-feed-with-asp-net/ 似乎我做的一切都是正确的,但是当我启动我的应用程序时 - 我有下一个错误或警报,nvm:
This XML file does not appear to have any style information associated with it. The document tree is shown below.
<rss version="2.0">
<channel>
<title>Name of the website</title>
<link>http://pudel.com</link>
<description>Short description of the site</description>
<item>
<title>Jenzyk Polski</title>
<link>http://localhost:56957/rss.aspx?ID=11</link>
<pubDate>Wed, 03 Apr 2013 00:00:00 GMT</pubDate>
<description>Co to jest?</description>
</item>
<item>
<title>Czy mowic pana zona po Polsku?</title>
<link>http://localhost:56957/rss.aspx?ID=13</link>
<pubDate>Tue, 02 Apr 2013 00:00:00 GMT</pubDate>
<description>Tak, bardzo dobze mowic</description>
</item>
<item>
<title>Kim jestes z pochodzenia?</title>
<link>http://localhost:56957/rss.aspx?ID=12</link>
<pubDate>Tue, 02 Apr 2013 00:00:00 GMT</pubDate>
<description>Jestes Polakiem</description>
</item>
</channel>
</rss>
[/XML]
当然,这种观点不是我计划要做的。那么,问题出在哪里?尝试用不同的浏览器打开——都一样。尝试将 web.config 中的编码从 UTF-8 更改为 WINDOWS-1251 - 都一样。
这是 rss.aspx.cs 页面的代码:
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;
namespace softacom.pb
{
public partial class rss : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
string connString = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
SqlConnection sqlConn = new SqlConnection();
sqlConn.ConnectionString = connString;
string sqlQuery = "SELECT TOP 10 newsID, Title, Date, Description FROM News ORDER BY Date DESC";
SqlCommand cmd = new SqlCommand();
cmd.Connection = sqlConn;
cmd.CommandType = CommandType.Text;
cmd.CommandText = sqlQuery;
sqlConn.Open();
RepeaterRSS.DataSource = cmd.ExecuteReader();
RepeaterRSS.DataBind();
sqlConn.Close();
}
protected string RemoveIllegalCharacters(object input)
{
string data = input.ToString();
data = data.Replace("&", "&");
data = data.Replace("\"", """);
data = data.Replace("'", "'");
data = data.Replace("<", "<");
data = data.Replace(">", ">");
return data;
}
}
}
这是 rss.ASPX
<%@ Page Language="C#" ContentType="text/xml" AutoEventWireup="true" CodeBehind="rss.aspx.cs" Inherits="softacom.pb.rss" %>
<asp:Repeater ID="RepeaterRSS" runat="server">
<HeaderTemplate>
<rss version="2.0">
<channel>
<title>Name of the website</title>
<link>http://pudel.com</link>
<description> Short description of the site</description>
</HeaderTemplate>
<ItemTemplate>
<item>
<title><%# RemoveIllegalCharacters(DataBinder.Eval(Container.DataItem, "Title"))%> </title>
<link>http://localhost:56957/rss.aspx?ID=<%# DataBinder.Eval(Container.DataItem, "newsID") %></link>
<pubDate><%# String.Format("{0:R}", DataBinder.Eval(Container.DataItem, "Date"))%> </pubDate>
<description><%# RemoveIllegalCharacters(DataBinder.Eval(Container.DataItem, "Description"))%></description>
</item>
</ItemTemplate>
<FooterTemplate>
</channel>
</rss>
</FooterTemplate>
</asp:Repeater>