我正在为我的asp.net项目制作一个Rss Feed,我找到了一个解决方案,但是只有当我在我的计算机上测试它并且我将它上传到服务器上时它才停止工作解析器错误... 我首先想到的是关于调试模式,但我省略了那部分而且我仍然得到了错误... 这是aspx代码:
<%@ Page ResponseEncoding="UTF-8" Language="C#" AutoEventWireup="true" debug="true" CodeFile="Default.aspx.cs" Inherits="mysite.feed.Default" %>
<%@ OutputCache Duration="300" VaryByParam="none" %>
这是aspx.cs代码:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Xml;
using System.Text;
using System.Configuration;
namespace mysite.feed
{
public partial class Default : System.Web.UI.Page
{
db_mysite context=new db_mysiteEntities();
protected void Page_Load(object sender, EventArgs e)
{
Response.Clear();
Response.ContentType = "application/rss+xml";
XmlTextWriter objX = new XmlTextWriter(Response.OutputStream, Encoding.UTF8);
objX.WriteStartDocument();
objX.WriteStartElement("rss");
objX.WriteAttributeString("version", "2.0");
objX.WriteStartElement("channel");
objX.WriteElementString("title", "mysite.com Rss Feed");
objX.WriteElementString("link", "mysite.com/");
objX.WriteElementString("description", "");
objX.WriteElementString("language", "en-us");
objX.WriteElementString("ttl", "60");
objX.WriteElementString("image", "");
objX.WriteElementString("lastBuildDate", String.Format("{0:R}", DateTime.Now));
var b = (from c in context.News where c.IsActive == true select c).ToList();
foreach (var newse in b)
{
int txt = newse.NewsID;
var g = (from c in context.News_Group_Connections
where c.NewsID == txt
join r in context.News_Group on c.NewsGroupID equals r.NewsGroupID
select r.NewsGroupTitle).First();
objX.WriteStartElement("item");
objX.WriteElementString("title", newse.NewsTitle);
objX.WriteElementString("author", "VBasic.net");
objX.WriteElementString("link", newse.NewsLinkAddress);
objX.WriteStartElement("guid");
objX.WriteAttributeString("isPermaLink", "true");
objX.WriteString("mysite.com/");
objX.WriteEndElement();
//objX.WriteElementString("pubDate", DateTime.Parse(newse.NewsDate.ToString()).ToString("MM/dd/yyyy"));
objX.WriteElementString("pubDate", String.Format("{0:R}", newse.NewsDate));
objX.WriteStartElement("category");
objX.WriteString(g);
objX.WriteEndElement();
objX.WriteElementString("description", newse.NewsDescription);
objX.WriteEndElement();
}
//while (dr.Read())
//{
// objX.WriteStartElement("NewsTitle");
// objX.WriteEndElement();
// objX.WriteElementString("description", dr["Article"].ToString().Substring(0, 100) + "..");
// objX.WriteEndElement();
//}
objX.WriteEndElement();
objX.WriteEndElement();
objX.WriteEndDocument();
objX.Flush();
objX.Close();
Response.End();
}
}
}
感谢...
编辑:第一行发生错误,消息为:
Server Error in '/' Application.
Parser Error
Description: An error occurred during the parsing of a resource required to service this request. Please review the following specific parse error details and modify your source file appropriately.
Parser Error Message: The file '/feed/Default.aspx.cs' does not exist.
Source Error:
Line 1: <%@ Page ResponseEncoding="UTF-8" Language="C#" AutoEventWireup="true" debug="true" CodeFile="Default.aspx.cs" Inherits="mysite.feed.Default" %>
Line 2:
Line 3: <%@ OutputCache Duration="300" VaryByParam="none" %>
Source File: /feed/default.aspx Line: 1
Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.34209