itunes rss 与 c# MVC
itunes rss with c# MVC
大家好,我正在尝试使用 asp.net MVC 为 iTunes 创建实时更新的 RSS 提要。我似乎无法验证供稿,当您导航到该页面时,xml 的格式与我使用网络表单制作时的格式不同。
这是视图
@model IEnumerable<lofbc.org.Models.media>
@{
Layout = null;
}
<?xml version="1.0" encoding="UTF-8" ?>
<rss xmlns:atom="http://www.w3.org/2005/Atom" xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd" xmlns:itunesu="http://www.itunesu.com/feed" version="2.0">
<channel>
<title>Life of Faith Bible Church Podcast</title>
<link>@Request.Url.Host</link>
<description>Welcome to Life of Faith Bible Church! We are dedicated to bringing you life-changing resources through our podcast and audio messages. You will find a wealth of material that will help you triumph in every area of life.</description>
<language>en-us</language>
<copyright>New Life Media copyright @DateTime.Now.Year</copyright>
<atom:link href="https://www.lofbc.org/rss" rel="self" type="application/rss+xml" />
<!--itunes specific-->
<itunes:author>Life of Faith Bible Church</itunes:author>
<itunes:summary>Welcome to Life of Faith Bible Church! We are dedicated to bringing you life-changing resources through our podcast and audio messages. You will find a wealth of material that will help you triumph in every area of life.</itunes:summary>
<itunes:owner>
<itunes:name>Life of Faith Bible Church</itunes:name>
<itunes:email>justin@lofbc.org</itunes:email>
</itunes:owner>
<itunes:explicit>No</itunes:explicit>
<itunes:image href="http://www.lofbc.org/rss/artwork/artwork.jpg" />
<itunes:category text="Religion & Spirituality"> </itunes:category>
@foreach (var item in Model)
{
var date = item.createdDate.ToString("yyyy");
var path = item.audioPath.ToString().Replace(".f4v", ".mp3");
<item>
<title>@item.title</title>
<url>http://lofbc-media.s3.amazonaws.com/@date/Audio/mp3/@path</url>
<pubDate>@item.createdDate.ToString("MMM dd, yyyy")</pubDate>
<description>@item.description</description>
<enclosure url="http://lofbc-media.s3.amazonaws.com/@item.createdDate.ToString("yyyy"))/Audio/mp3/@item.audioPath.ToString().Replace(".f4v", ".mp3")" length="" type="audio/mpeg" />
<itunes:summary>@item.description</itunes:summary>
</item>
}
</channel>
</rss>
这是控制器
using lofbc.org.context;
using lofbc.org.Models;
using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Linq;
using System.Web;
using System.Web.Mvc;
namespace lofbc.org.Controllers
{
public class rssController : Controller
{
// GET: rss
public ActionResult Index()
{
using (ServiceArchivesEntities db = new ServiceArchivesEntities())
{
try
{
DateTime startDate = DateTime.Parse("01/01/2015 00:00:00");
var MT = (from a in db.tbl_media
join b in db.tbl_media_ministers
on a.MinisterID equals b.ID
select new media
{
id = a.ID,
createdDate = (DateTime)a.CreatedDate,
title = a.Title,
minister = b.Title + " " + b.FirstName + " " + b.LastName,
audioPath = a.PathToAudio,
videoPath = a.PathToVideo,
views = a.Views,
listens = a.Listens,
status = a.Status
}).Where(t => t.status == 2 && t.createdDate >= startDate).OrderByDescending(t => t.createdDate).Take(100).ToList();
return View(MT);
}
catch (SqlException ex)
{
Response.Write(ex.ToString());
return View();
}
}
}
}
}
<itunes:category text="Religion & Spirituality"> </itunes:category>
需要
<itunes:category text="Religion & Spirituality"> </itunes:category>
iTunes 也可能反对 <?xml
之前的额外空行。在页面顶部尽可能紧密地打包 Razor 代码:
@model IEnumerable<lofbc.org.Models.media>
@{ Layout = null; }
<?xml version="1.0" encoding="UTF-8" ?>
<rss xmlns:atom="http://www.w3.org/2005/Atom" ....
大家好,我正在尝试使用 asp.net MVC 为 iTunes 创建实时更新的 RSS 提要。我似乎无法验证供稿,当您导航到该页面时,xml 的格式与我使用网络表单制作时的格式不同。
这是视图
@model IEnumerable<lofbc.org.Models.media>
@{
Layout = null;
}
<?xml version="1.0" encoding="UTF-8" ?>
<rss xmlns:atom="http://www.w3.org/2005/Atom" xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd" xmlns:itunesu="http://www.itunesu.com/feed" version="2.0">
<channel>
<title>Life of Faith Bible Church Podcast</title>
<link>@Request.Url.Host</link>
<description>Welcome to Life of Faith Bible Church! We are dedicated to bringing you life-changing resources through our podcast and audio messages. You will find a wealth of material that will help you triumph in every area of life.</description>
<language>en-us</language>
<copyright>New Life Media copyright @DateTime.Now.Year</copyright>
<atom:link href="https://www.lofbc.org/rss" rel="self" type="application/rss+xml" />
<!--itunes specific-->
<itunes:author>Life of Faith Bible Church</itunes:author>
<itunes:summary>Welcome to Life of Faith Bible Church! We are dedicated to bringing you life-changing resources through our podcast and audio messages. You will find a wealth of material that will help you triumph in every area of life.</itunes:summary>
<itunes:owner>
<itunes:name>Life of Faith Bible Church</itunes:name>
<itunes:email>justin@lofbc.org</itunes:email>
</itunes:owner>
<itunes:explicit>No</itunes:explicit>
<itunes:image href="http://www.lofbc.org/rss/artwork/artwork.jpg" />
<itunes:category text="Religion & Spirituality"> </itunes:category>
@foreach (var item in Model)
{
var date = item.createdDate.ToString("yyyy");
var path = item.audioPath.ToString().Replace(".f4v", ".mp3");
<item>
<title>@item.title</title>
<url>http://lofbc-media.s3.amazonaws.com/@date/Audio/mp3/@path</url>
<pubDate>@item.createdDate.ToString("MMM dd, yyyy")</pubDate>
<description>@item.description</description>
<enclosure url="http://lofbc-media.s3.amazonaws.com/@item.createdDate.ToString("yyyy"))/Audio/mp3/@item.audioPath.ToString().Replace(".f4v", ".mp3")" length="" type="audio/mpeg" />
<itunes:summary>@item.description</itunes:summary>
</item>
}
</channel>
</rss>
这是控制器
using lofbc.org.context;
using lofbc.org.Models;
using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Linq;
using System.Web;
using System.Web.Mvc;
namespace lofbc.org.Controllers
{
public class rssController : Controller
{
// GET: rss
public ActionResult Index()
{
using (ServiceArchivesEntities db = new ServiceArchivesEntities())
{
try
{
DateTime startDate = DateTime.Parse("01/01/2015 00:00:00");
var MT = (from a in db.tbl_media
join b in db.tbl_media_ministers
on a.MinisterID equals b.ID
select new media
{
id = a.ID,
createdDate = (DateTime)a.CreatedDate,
title = a.Title,
minister = b.Title + " " + b.FirstName + " " + b.LastName,
audioPath = a.PathToAudio,
videoPath = a.PathToVideo,
views = a.Views,
listens = a.Listens,
status = a.Status
}).Where(t => t.status == 2 && t.createdDate >= startDate).OrderByDescending(t => t.createdDate).Take(100).ToList();
return View(MT);
}
catch (SqlException ex)
{
Response.Write(ex.ToString());
return View();
}
}
}
}
}
<itunes:category text="Religion & Spirituality"> </itunes:category>
需要
<itunes:category text="Religion & Spirituality"> </itunes:category>
iTunes 也可能反对 <?xml
之前的额外空行。在页面顶部尽可能紧密地打包 Razor 代码:
@model IEnumerable<lofbc.org.Models.media>
@{ Layout = null; }
<?xml version="1.0" encoding="UTF-8" ?>
<rss xmlns:atom="http://www.w3.org/2005/Atom" ....