The BlogEngine.NET Syndication Handler throws exceptions when Server Offset is Positive
The syndication handler will throw an exception if you use a positive value for the Server Time Offset setting. This is because the response doesn't allow the modification time stamp to be in in the future and the offset makes it the future. Here is the SetHeaderInformation method found in the BlogEngine.Core.Web.HttpHandlers.SyndicationHandler.
1: /// <summary>
/// Sets the response header information.
/// </summary>
/// <param name="context">An <see cref="HttpContext"/> object that provides references to the intrinsic server objects (for example, <b>Request</b>, <b>Response</b>, <b>Session</b>, and <b>Server</b>) used to service HTTP requests.</param>
/// <param name="items">The collection of <see cref="IPublishable"/> instances used when setting the response header details.</param>
/// <param name="format">The format of the syndication feed being generated.</param>
/// <exception cref="ArgumentNullException">The <paramref name="context"/> is a null reference (Nothing in Visual Basic) -or- the <paramref name="posts"/> is a null reference (Nothing in Visual Basic).</exception>
private static void SetHeaderInformation(HttpContext context, List<IPublishable> items, SyndicationFormat format)
{
DateTime lastModified = DateTime.MinValue;
foreach (IPublishable item in items)
{
if (item.DateModified > lastModified)
lastModified = item.DateModified;
}
switch (format)
{
case SyndicationFormat.Atom:
context.Response.ContentType = "application/atom+xml";
context.Response.AppendHeader("Content-Disposition", "inline; filename=atom.xml");
break;
case SyndicationFormat.Rss:
context.Response.ContentType = "application/rss+xml";
context.Response.AppendHeader("Content-Disposition", "inline; filename=rss.xml");
break;
}
if (Utils.SetConditionalGetHeaders(lastModified))
context.Response.End();
}
The DateModified property adds the time offset, so we need to remove the time offset (thus making it local time again). The lastModified value should only be corrected when it is not the minimum value, as you can't go less the minimum value. Insert the following code at line 16.
1: if (lastModified != DateTime.MinValue)
lastModified = lastModified.AddHours(-BlogSettings.Instance.Timezone);
License and Code
The code in this post is released under the Microsoft Reciprocal License, which is the license for BlogEngine.NET.