asp.net怎么样把整个网站的页面都变成html
我想提高我的网站访问速度,所以想把整个网站的页面生成html文件 请教各位高手 能不能给个例子 给我看看! 谢谢!
------解决方案--------------------
可以的吧 我就是这么做的 我都是修改了页面就重新生成那个html
using System;
using System.Data;
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.IO;
using LTP.Common;
/// <summary>
/// staticPage 的摘要说明
/// 页面静态处理
/// </summary>
public class staticPage : Page
{
public staticPage()
{
//
// TODO: 在此处添加构造函数逻辑
//
}
private DataTable dt;
//自动生成页面开始//
protected override void OnPreInit(EventArgs e)
{
try
{
string stType = Request.QueryString["type"] == null ? "main" : Request.QueryString["type"].ToString();
string stID = Request.QueryString["id"] == null ? "" : Request.QueryString["id"].ToString();
string stPath = Request.QueryString["type"] == null ? "" : Request.QueryString["type"].ToString();
string P = System.IO.Path.GetFileName((this.Page.Request.PhysicalPath.ToString()).ToLower()).Replace(".aspx", "");
string str = string.Empty;
if (stType == "main")
{
str = StringPlus.ReplaceChar(P) + ".html";
}
else
{
str = StringPlus.ReplaceChar(P) + "/JoinDetails" + stID + ".html";
}
//string str = P + ".html";
string Path = Server.MapPath(str);
System.IO.FileInfo aFileInfo = new System.IO.FileInfo(Path);
if (aFileInfo.Exists)
{
TimeSpan M = System.DateTime.Now - aFileInfo.LastWriteTime;
if (M.TotalSeconds > 1)
aFileInfo.Delete();
else
Server.Transfer(str, true);
// Server.Transfer("index.html", true);
}
base.OnPreInit(e);
}
catch (Exception ex)
{
Response.Write(ex.Message.ToString());
//Public.Constant.Show(this, ex.Message.ToString());
//JS.WebError(@Page.Server.MapPath("~/index.aspx"), ex.Message.ToString(), Page.Title+" Static Error!");
}
}
protected override void OnInitComplete(EventArgs e)
{
try
{
/*
DmPagekey mdKeys = new DmPagekey();
IfPagekey dfKeys = new IfPagekey();
string pageName= System.IO.Path.GetFileName((this.Page.Request.PhysicalPath.ToString()).ToLower());
mdKeys = dfKeys.GetPagekeyInfo(pageName);
if (pageName.Length >= 1)
{
if (mdKeys != null)
{
Page.Title = mdKeys.pageTitle;
//Description
HtmlMeta desc = new HtmlMeta();
desc.Name = "Description";
desc.Content = mdKeys.pageDescription;
if (desc != null)
{
//hhead.Controls.Add(desc);
Page.Header.Controls.Add(desc);
}