English 中文(简体)
ASP. 创建RSS饲料的网络,没有错误,没有数据
原标题:ASP.NET creating RSS feed, no error but no data

OK for the record, I m MUCH more familiar with Java and RnR than any .NET. I have fixed a few bugs in a function here and there and Googled a few new "features" here and there but it s not my expertise. OK cavets out of the way, here s my issue, I need to create a RSS feed for our site built in ASP.NET. Google turned up a few solutions, but I used this one as an example: http://www.aspfree.com/c/a/C-Sharp/Creating-an-RSS-Feed-with-ASP-Net-Written-in-C-Sharp/

Oddly, I get it all to work with no errors that I can see but I only get a blank page when I run it. I ve tested the SQL, it works and returns the rows I want but I don t know how to diagnose if it s connecting to the DB or not or why it s not returning anything. Here s the code:

页: 1

using System;
using System.Text;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Xml;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Diagnostics;


       //Class for returning RSS feed Data

   public partial class rss : System.Web.UI.Page
{

    private void Page_Load(object sender, System.EventArgs e)
    {
        string sSource;
        string sLog;
        string sEvent;
        sSource = "RSS Feed";
        sLog = "Application";
        sEvent = "Database Connectiont";
       // Connect to the Database
       SqlConnection myConnection = new SqlConnection("Data Source=localhost;Initial Catalog=events;Persist Security Info=True;User ID=wa;Password=password;");
       // Retrieve the SQL query results and bind it to the Repeater
       const string SQL_QUERY = "SELECT EventName, Comments, URL, StartDate FROM event WHERE SaleDateTo > getdate() AND SaleDateFrom < getdate() AND redirecttourl is not null ORDER BY EventDate";
       SqlCommand myCommand = new SqlCommand(SQL_QUERY, myConnection);
       bool IsDbAvailable = true;
       try {
           myConnection.Open();
           rptRSS.DataSource = myCommand.ExecuteReader(CommandBehavior.CloseConnection);
           rptRSS.DataBind();
           myConnection.Close();
           }
           catch {
                IsDbAvailable = false;
                if (!EventLog.SourceExists(sSource))
                        EventLog.CreateEventSource(sSource,sLog);
            }
        finally {
            myConnection.Close();
        }     
    }

    protected string FormatForXML(object input)
    {
       string data = input.ToString(); //cast input to string

       // replace those characters disallowed in XML documents
       data = data.Replace("&", "&amp;");
       data = data.Replace(""", "&quot;");
       data = data.Replace(" ", "&apos;");
       data = data.Replace("<", "&lt;");
       data = data.Replace(">", "&gt;");

       return data;
    }
}

rss.aspx:

    <%@ Page language="c#" CodeFile="rss.aspx.cs" ContentType="text/xml" AutoEventWireup="false" Inherits="rss"%>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >

<asp:Repeater id="rptRSS" runat="server">

  <HeaderTemplate>
    <rss version="2.0">
      <channel>
        <title>TA On-Sale Feed</title>
        <link>http://www.website.com/rss.aspx</link>
        <description>All events current on-sale</description>
  </HeaderTemplate>

    <itemTemplate>
    <event>
    <title><%#FormatForXML(DataBinder.Eval(Container.DataItem,"EventName"))%>
    </title>
    <description>
    <%#FormatForXML(DataBinder.Eval(Container.DataItem, "Comments"))%>
    </description>
    <link>http://order.ticketalternative.com<%#DataBinder.Eval(Container.DataItem, "url")%>
    </link>
    <eventdate>
    <%#DataBinder.Eval(Container.DataItem, "StartDate")%>
    <eventdate>
    </event>
    </ItemTemplate>
     <FooterTemplate>
          </channel>
        </rss>
      </FooterTemplate>
    </asp:Repeater>
</html>
最佳回答

将数据集/数据制成数据集,使用DataAdpter,然后将数据集/数据贴在侵权行为中。 数据来源。

问题回答

暂无回答




相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Transaction handling with TransactionScope

I am implementing Transaction using TransactionScope with the help this MSDN article http://msdn.microsoft.com/en-us/library/system.transactions.transactionscope.aspx I just want to confirm that is ...

System.Web.Mvc.Controller Initialize

i have the following base controller... public class BaseController : Controller { protected override void Initialize(System.Web.Routing.RequestContext requestContext) { if (...

Microsoft.Contracts namespace

For what it is necessary Microsoft.Contracts namespace in asp.net? I mean, in what cases I could write using Microsoft.Contracts;?

Separator line in ASP.NET

I d like to add a simple separator line in an aspx web form. Does anyone know how? It sounds easy enough, but still I can t manage to find how to do it.. 10x!

热门标签