public void ProcessTrackback(HttpContext context, bool bRequireID)
{
HttpRequest request = context.Request;
HttpResponse response = context.Response;
response.Buffer = false;
response.Clear();
response.ContentType = "application/xml";
XmlWriterSettings settings = new XmlWriterSettings();
settings.Indent = true;
settings.Encoding = Encoding.UTF8;
settings.CheckCharacters = true;
XmlWriter writer = XmlWriter.Create(response.Output, settings);
if (request.Form.AllKeys.Count() < 6 && (!string.IsNullOrEmpty(request["id"]) || !bRequireID)
&& !string.IsNullOrEmpty(request["excerpt"])
&& !string.IsNullOrEmpty(request["blog_name"])) {
string blogId = string.Empty;
if (!string.IsNullOrEmpty(request["id"]))
blogId = request["id"];
if (!bRequireID && string.IsNullOrEmpty(blogId)) {
blogId = request.Path;
}
string blogTitle = string.Empty;
if (!string.IsNullOrEmpty(request["blog_name"]))
blogTitle = request["blog_name"];
string url = string.Empty;
if (!string.IsNullOrEmpty(request["url"]))
url = request["url"];
string title = string.Empty;
if (!string.IsNullOrEmpty(request["title"]))
title = request["title"];
string excerpt = string.Empty;
if (!string.IsNullOrEmpty(request["excerpt"]))
excerpt = request["excerpt"];
TrackBackInfo tb = new TrackBackInfo {
RequestSourceURL = url,
BlogName = blogTitle,
BlogPostID = blogId,
BlogPostTitle = title,
BlogExcerpt = excerpt
};
if (request.HttpMethod == "POST") {
// Store trackback based on the id parameter
GenerateSuccessResponse(request, writer, tb);
} else {
GenerateErrorResponse(2, "Only HTTP POST verb can be used to send trackbacks", writer);
}
} else {
GenerateErrorResponse(1, "Item identifier is missing", writer);
}
}