日期:2014-05-18  浏览次数:20529 次

请教 我有个asp.net2.0 论坛 如何把他转化为静态论
如题

------解决方案--------------------
Url重写 1.aspx/12345 request.pathinfo
访问动态页面,根据此动态页面生成静态页面。
using System;
using System.Data;
using System.Data.OleDb;
using System.Configuration;
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 System.Drawing;
using System.Text.RegularExpressions;
using System.IO;
using System.Reflection;
using System.Collections.Generic;


public class DynamicTurnStatic
{
/// <summary>
/// 生成新的静态页面,如果以前已经存在相应的静态页面,则生成新内容,原文件名不变
/// </summary>
/// <param name= "DynamicUrl "> 动态页面地址 ~/newsview.aspx?url=2 </param>
/// <param name= "StaticPath "> 静态页面存放的文件夹相对路径 ~/22/22/ </param>
/// <param name= "NewsID "> 新闻ID </param>
/// <param name= "UserID "> 用户ID </param>
/// <param name= "ExistFileName "> 以前存放此新闻的静态页面文件名 1.html </param>
/// <returns> 返回静态页面文件名 2.html </returns>
public static string GetStaticUrl(string DynamicUrl, string StaticPath, string NewsID, string UserID, string ExistFileName)
{
try
{
//静态文件名
string StaticUrl = DateTime.Now.ToString( "yyyymmddhhmmss ") + UserID + NewsID + ".html ";
//静态文件所属目录处理
if (!Directory.Exists(HttpContext.Current.Server.MapPath(StaticPath)))
{
Directory.CreateDirectory(HttpContext.Current.Server.MapPath(StaticPath));
}

if (!string.IsNullOrEmpty(ExistFileName))
{
DelNewsFile(StaticPath + ExistFileName);
StaticUrl = ExistFileName;
}
StreamWriter sw = new StreamWriter(HttpContext.Current.Server.MapPath(StaticPath) + StaticUrl, false, System.Text.Encoding.GetEncoding( "GB2312 "));
HttpContext.Current.Server.Execute(DynamicUrl, sw, true);
sw.Flush();
sw.Close();
return StaticUrl;
}
catch
{
return null;
}

}
/// <summary>
/// 生成新的静态页面,如果以前已经存在相应的静态页面,则生成新内容,原文件名不变
/// </summary>
/// <param name= "DynamicUrl "> 动态页面地址 ~/newsview.aspx?url=2 </param>
/// <param name= "StaticPath "> 静态页面存放的文件夹相对路径 ~/22/22/ </param>
/// <param name= "NewsID "> 新闻ID </param>
/// <param name= "UserID "> 用户ID </param>
/// <returns> 返回静态页面文件名 2.html </returns>
public static string GetStaticUrl(string DynamicUrl, string StaticPath, string NewsID, string UserID)
{
try
{
//静态文件名
string StaticUrl = DateTime.Now.ToString( "yyyymmddhhmmss ") + UserID + NewsID + ".html ";
//静态文件所属目录处理
if (!Directory.Exists(HttpContext.Current.Server.MapPath(StaticPath)))
{
Directory.CreateDirectory(HttpContext.Current.Server.MapPath(StaticPath));
}


StreamWriter sw = new StreamWriter(HttpContext.Current.Server.MapPath(StaticPath) + StaticUrl, false, System.Text.Enc