form处的代码:
评论内容:
remark.aspx中相关操作的代码:
protected override void OnLoad(EventArgs e)
{
base.OnLoad (e);
int nArticleID = int.MinValue;//文章id
int nClassID = int.MinValue;//分类id
try
{
//获取传入参数
nArticleID = int.Parse(this.Request.QueryString["articleid"]);
nClassID = int.Parse(this.Request.QueryString["classid"]);
}
catch
{
}
//检查有效性
if(nArticleID < 1 || nClassID < 1)
{
this.Response.Redirect("/error.html",true);
}
string sRemarkBody = this.Request.Params["remarkbody"];
//格式:/show.aspx?id=456&cid=123
string sFrom = string.Concat("/show.aspx?id=",nArticleID,"&cid=nClassID);
//格式:/news/123/456.html
string sTo = string.Concat("/news/",nClassID,"/",nArticleID,".html");
if(sRemarkBody != null && sRemarkBody.Length > 0)
{
//添加评论
InsertRemark(nArticleID);
//生成静态页面
MakeStatic(sFrom,this.MapPath(sTo));
}
//转向静态页面
this.Response.Redirect(sTo,true);
}
这样处理的静态页面在普通浏览时与其它的静态页面完全一样,只是在发评论时对待更新评论的程序,整体的招待速度还是很快的。
第二种情况,新闻分类列表页面。此类页面在管理新闻的时候变化会非常大,即使采用后台管理也非常的不便。这就需要一些程序来帮助管理员管理这些页面。程序思路在前面已经提过,在此给出能够实际应用的程序代码。
protected override void OnLoad(EventArgs e)
{
base.OnLoad (e);
int nClassId = int.MinValue;//分类id
int nPage = int.MinValue;//页码
try
{
//获取传入参数
nClassID = int.Parse(this.Request.QueryString("classid"));
nPage = int.Parse(this.Request.QueryString("page");
}
catch
{
}
//检查有效性
if(nClassID < 1)
{
this.Response.Redirect("/error.html",true);
}
else if(nPage < 1)
{
nPage = 1;
}
//格式:/list.aspx?cid=123&page=456
string sFrom = string.Concat("/list.aspx?cid=",nClassID,"&page=",nPage);
//格式:/news/123/default456.html
string sTo = string.Concat("/news/",nClassID,"/default",((nPage==1) ? ("") : (nPage)),".html");
string sPath = this.MapPath(sTo);
if(!File.Exists(sPath))
{
//文件不存在时,创建静态页面
MakeStatic(sFrom,sTo);
}
else
{
TimeSpan ts = DateTime.Now - File.GetLastWriteTime(sPath);
if(ts.TotalDays > 1)
{
//文件已存在,但是存在时间过长,需更新
MakeStatic(sFrom,sTo);
}
}
//转向静态页面
this.Response.Redirect(sTo,true);
}