在线等:请教关于ASP.NET生成整站静态页面的问题

g82_tt 2008-05-20 11:34:42
正在做一个网站~要求实现整站的全静态~包括首页和栏目首页~而且各个栏目页面存放的文件夹是可以动态更改的~内页的文件名也是后台中定义的~
想问一下有没有什么好的整站生成策略以及个别内页内容的更新策略
模板标签替换已经实现了~~现在的问题是生成的整个站点的结构以及对这个结构的更新处理不好~~头大~~

举个例子~~
我现在修改了一个内页的标题和内容~我要采用什么策略来更新与这个内页相关的栏目首页、栏目列表页、整站首页以及与它处于同一级的带有“上一篇文章”/“下一篇文章”这类链接的其它内页~~~程序如何知道应该重新生成哪些相关的页面呢?

注:服务器在国外,访问速度比较慢而且站点的数据量比较大,肯定不能动不动就重新生成整站或整个栏目,所以想请各位高人给出一个合理的更新策略。能附上点源代码更好:)

先谢谢各位了!!!小弟在线等待各位高见……
...全文
155 14 打赏 收藏 转发到动态 举报
写回复
用AI写文章
14 条回复
切换为时间正序
请发表友善的回复…
发表回复
sunlovesea 2008-05-20
  • 打赏
  • 举报
回复
学习..
job_2006 2008-05-20
  • 打赏
  • 举报
回复
顶一下,关注
zpcoder 2008-05-20
  • 打赏
  • 举报
回复
    protected void Button1_Click(object sender, EventArgs e)
{
string url = "http://" + Request.Url.Authority + "/default.aspx";
new System.Net.WebClient().DownloadFile(url, Server.MapPath("~/default.html"));
Response.Redirect("default.html");

Response.Write(Request.Url.DnsSafeHost);
}
gongsun 2008-05-20
  • 打赏
  • 举报
回复
帮顶者有分...
HarleyTung 2008-05-20
  • 打赏
  • 举报
回复

namespace EFPlatform_CodeGenerator
{
public partial class _Default : System.Web.UI.Page
{
private string outputPath;
private string categoryFileName;
private string productFileName;
private static DbProviderFactory dbFactory;
private DbConnection connection;
protected void Page_Load(object sender, EventArgs e)
{
outputPath = Server.MapPath("./");
categoryFileName = string.Format(@"{0}\Template\Category.html", outputPath);
productFileName = string.Format(@"{0}\Template\Product.html", outputPath);
string currentConnection = ConfigurationManager.AppSettings["Connection"];
ConnectionStringSettings css = ConfigurationManager.ConnectionStrings[currentConnection];
this.GetConnection(css);
}
private void GenerateCategory()
{
string template = Helper.ReadTextFile(categoryFileName);
Generator gen = new Generator(template);
gen.ParseTemplate();
Region rgnTitle = gen.Regions["Title"];
Region rgnCategory = gen.Regions["Category"];
Region rgnProducts = gen.Regions["Products"];
Region rgnNavigator = gen.Regions["Navigator"];
if (rgnTitle == null || rgnCategory == null || rgnProducts == null || rgnNavigator == null)
{
Response.Write("Missing region.");
return;
}
int categoryId;
string outputFileName;
DataView dvCategory = this.GetCategoryTable().DefaultView;
Pager pgrCategory = new Pager(1, dvCategory.Count);
for (int i = 0; i < pgrCategory.PageCount; i++)
{
rgnTitle.DataSource = (string)dvCategory[i]["CategoryName"]; //Use a string as data source
rgnCategory.DataSource = dvCategory[i]; //Use a DataRowView object as data source
pgrCategory.CurrentPage = i + 1;
rgnNavigator.DataSource = pgrCategory; //Use a Pager object as data source
categoryId = (int)dvCategory[i]["CategoryID"];
rgnProducts.DataSource = this.GetProductTable(categoryId); //Use a DataTable object as data souce
outputFileName = string.Format(@"{0}\Html\Category{1}.html", outputPath, categoryId);
Helper.WriteTextFile(outputFileName, gen.Generate());
}
}
private void GenerateProduct()
{
string template = Helper.ReadTextFile(productFileName);
Generator gen = new Generator(template);
gen.ParseTemplate();
Region rgnTitle = gen.Regions["Title"];
Region rgnProduct = gen.Regions["Product"];
Region rgnNavigator = gen.Regions["Navigator"];
if (rgnTitle == null || rgnProduct == null || rgnNavigator == null)
{
Response.Write("Missing region.");
return;
}
string outputFileName;
List<Product> productList = this.GetProductList();
Pager pgrProduct = new Pager(1, productList.Count);
for (int i = 0; i < pgrProduct.PageCount; i++)
{
rgnTitle.DataSource = productList[i].CategoryName; //Use a string as data source
rgnProduct.DataSource = productList[i]; //Use a Product object as data source
pgrProduct.CurrentPage = i + 1;
rgnNavigator.DataSource = pgrProduct; //Use a Pager object as data source
outputFileName = string.Format(@"{0}\Html\Product{1}.html", outputPath, productList[i].ProductID);
Helper.WriteTextFile(outputFileName, gen.Generate());
}
}

#region DataSourcePreparing
private void GetConnection(ConnectionStringSettings css)
{
if (dbFactory == null)
{
dbFactory = DbProviderFactories.GetFactory(css.ProviderName);
}
this.connection = dbFactory.CreateConnection();
this.connection.ConnectionString = css.ConnectionString;
}
private DataTable GetCategoryTable()
{
string commandText = "SELECT CategoryID, CategoryName, Description FROM Categories";
DbDataAdapter da = dbFactory.CreateDataAdapter();
da.SelectCommand = dbFactory.CreateCommand();
da.SelectCommand.Connection = this.connection;
da.SelectCommand.CommandText = commandText;
DataTable dt = new DataTable();
this.connection.Open();
da.Fill(dt);
this.connection.Close();
return dt;
}
private DataTable GetProductTable(int categoryId)
{
string commandText = string.Format("SELECT * FROM Products WHERE CategoryID = {0}", categoryId);
DbDataAdapter da = dbFactory.CreateDataAdapter();
da.SelectCommand = dbFactory.CreateCommand();
da.SelectCommand.Connection = this.connection;
da.SelectCommand.CommandText = commandText;
DataTable dt = new DataTable();
this.connection.Open();
da.Fill(dt);
this.connection.Close();
return dt;
}
private List<Product> GetProductList()
{
string commandText = "SELECT p.*, c.CategoryName, s.CompanyName FROM (Products AS p INNER JOIN Categories AS c ON p.CategoryID = c.CategoryID) INNER JOIN Suppliers AS s ON p.SupplierID = s.SupplierID ORDER BY p.ProductID";
DbCommand command = this.connection.CreateCommand();
command.CommandText = commandText;
List<Product> productList = new List<Product>();
Product product;
this.connection.Open();
using (DbDataReader dr = command.ExecuteReader())
{
while (dr.Read())
{
product = new Product();
Helper.FillModel(product, dr);
productList.Add(product);
}
}
this.connection.Close();
return productList;
}
protected void Button1_Click(object sender, EventArgs e)
{
this.GenerateCategory();
}
protected void Button2_Click(object sender, EventArgs e)
{
this.GenerateProduct();
}
}
}
milozy1983 2008-05-20
  • 打赏
  • 举报
回复
服务器内存要大点,另外菜单也要重新生成的话可以考虑把菜单放在一个iframe里,其他能重复使用的地方也尽量用iframe.我自己的站是全部页面生成静态页面的,但规模不大.http://www.cbgame.net
hackerxxw 2008-05-20
  • 打赏
  • 举报
回复
我也想多知道一些这方面的技术

绑定!!
LutzMark 2008-05-20
  • 打赏
  • 举报
回复
可以参考discuz .net生成模板的做法 不过dz是伪静态的..
guying999 2008-05-20
  • 打赏
  • 举报
回复
对于静态的新闻页面我不建议每修改和删除一次就重新生成列表页,首页可以定时生成,比如:一分钟生成一次,列表页在数据添加的时候可以级联更新和它有关的列表页,关于删除不用再重新生成所有的关联页面,只需要把删除页面的内容换成空白或者已删除提示即可,关于修改除了修改标题级联更新关联页面有点作用之外,其他项的修改对其他页面的影响都不是很大,所以修改可以忽略。
另外关于级联的页面你可以做一个页面关系表,比如这个类型的静态页面要更新哪个页面,有了这种关系就好级联更新了
air_space 2008-05-20
  • 打赏
  • 举报
回复
单个页面生成静态的容易,关键是相互之间的关联如何实现,

比如:一个新闻列表,每页20条来说,每添加一条,是否就要重新更新列表?如果本来就有几十个分页了,是否这几十分页都要重新更新一下?
zhnzzy 2008-05-20
  • 打赏
  • 举报
回复
个看你数据库如何设置的了
g82_tt 2008-05-20
  • 打赏
  • 举报
回复
楼上的兄弟~~谢谢你的回答~~~我不是要生成所有页面~~~而是在添加、修改、删除单个信息(也就是单个页面)的时候更新与它相关的网站首页、栏目首页及其它相关页面的思路~~~而不是每改动一个信息就要重新生成整站啊~~
caicoko 2008-05-20
  • 打赏
  • 举报
回复
把所有的生成其他页面的方法汇总一下就是生成所有的静态页面了

g82_tt 2008-05-20
  • 打赏
  • 举报
回复
To: milozy1983
这个站目前用的是虚拟主机,内存和其它的硬件配置我也动不了~~但是用iframe是要考虑一下了~~还有就是这个站规模比较大而且文件存放的路径都是自定义的,管理起来很麻烦~~基本上就是一个栏目固定的通用CMS了~~~感谢你的回答!

To:dyjqk
兄台给出来的是生成页面的代码~这个我已经实现了,我需要的是文件存储结构方面的逻辑或者思路。还有就是在添加、编辑或删除过程中重新生成相关文件的逻辑和思路~~~~也感谢你的回答!

62,074

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧