我在Umbraco中有一个内容模板,用于呈现RSS提要。
@inherits Umbraco.Web.Mvc.UmbracoViewPage<ContentModels.RSS>
@using ContentModels = Umbraco.Web.PublishedContentModels;
@{
Layout = null;
}<?xml version="1.0"?>
@{
var siteUrl = Request.Url.ToString().ToLower().Replace("/rss","");
var selection = Model.Root().Descendants()
.Where(x => x.IsVisible())
.OfType<NewsArticle>();
}
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
<channel>
<title>GlobalHealth News</title>
<link>http://www.example.com</link>
<description>Example News Feed</description>
<copyright>Copyright Example. All rights reserved.</copyright>
@foreach(var item in selection){
var useUrl = "";
if(item.HyperLink != string.Empty){
useUrl = item.HyperLink;
}
<item>
<title>@item.HyperLink</title>
<description>@item.Description</description>
@Html.Raw("<link>") @useUrl @Html.Raw("</link>")
<pubDate>@item.PublishDate.ToShortDateString()</pubDate>
</item>
}
</channel>
</rss>
我升级到Umbraco 8之前,此模板可以正常工作。升级后,将XML内容包装在这样的HTML响应中,
<html>
<head>
</head>
<body>
<!-- XML content -->
</body>
</html>
如何摆脱包装纸?
将响应内容类型设置为text/xml
,
@{
Layout = null;
Response.ContentType = "text/xml";
}