BlogEngine中载入未审核的评论
一直苦于在blogengine中没有页面来统一管理待审核的评论,今天拼了二行代码。
在admin/pages下新建commentlist.aspx页面,masterpage选admin1.master
masterpage选admin1.master
<%@ Page Language="C#" MasterPageFile="~/admin/admin1.master" AutoEventWireup="true" CodeFile="commentlist.aspx.cs" Inherits="admin_Pages_commentlist" Title="评论列表" %>
<asp:Content ID="Content1" ContentPlaceHolderID="cphAdmin" Runat="Server">
<asp:Repeater ID="list_main" runat="server">
<HeaderTemplate>
<table width="100%" class="myTable" >
<thead><td>ID</td><td>用户名</td><td>发表时间</td><td>原文链接</td></thead>
</HeaderTemplate>
<ItemTemplate>
<tr><td><%# Eval("ID") %></td><td><%# Eval("Author")%></td><td><%# Eval("DateCreated")%></td><td><a href="<%# Eval("AbsoluteLink")%>" target="_blank"><%# Eval("AbsoluteLink")%></a></td></tr>
</ItemTemplate>
<FooterTemplate>
<tfoot>
<td colspan="4">统计:共有评论 <b><%=CommentCounts %></b> 条,其中待认证评论 <i><%=UnApprovedComments %></i> 条</td>
</tfoot>
</table>
</FooterTemplate>
</asp:Repeater>
</asp:Content>
commentlist.aspx.cs:
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using BlogEngine.Core;
using System.Collections.Generic;
public partial class admin_Pages_commentlist : System.Web.UI.Page
{
protected string CommentCounts = "";
protected string UnApprovedComments = "";
protected void Page_Load(object sender, EventArgs e)
{
BindComments();
}
/// <summary>
/// 绑定未通过评论
/// </summary>
void BindComments()
{
List<BlogEngine.Core.Comment> list = new List<Comment>();
int i = 0, j = 0;
foreach (Post post in Post.Posts)
{
if (post.Comments.Count == 0)
continue;
i += post.Comments.Count;
foreach (Comment comment in post.Comments)
{
if (comment.Email == "trackback" || comment.Email == "pingback" || comment.IsApproved==true)
continue;
list.Add(comment);
j++;
}
}
this.list_main.DataSource = list;
this.list_main.DataBind();
CommentCounts = i.ToString("###,###");
UnApprovedComments = j.ToString("###,###");
}
}
web.sitemap中添加导航即可,这样在管理页面中就可以对待审核的评论进行统一管理了