关于纯静态的问题。 纯静态怎么生成?思路是什么? 有例子最好。 那么生成纯静态之后,怎么对数据进行交互。比如门户网站上的一个纯静态新闻页面,用户在新闻里面写评论。 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 制作静态模板(html)替换模板标签 生成静态页面数据交互JS+AJAX “数据交互JS+AJAX”这一步骤有更具体的思路吗? 利用ajax 将输入的内容返回到服务端保存,就是这个过程。当然相关脚本与模板页一同生成。 纯静态可以减少大量的数据库交互,缓存交互,页面上的动态内容可以由ajax控制或者iframe嵌套aspx 你可以用JSON。JQuery+ASHX.这就可以实现静态的.完全脱离控件 直接 private void Page_Load(object sender, System.EventArgs e) { try { string cription = ""; myDt = cl.GetTable();//获取自己数据库中的一个table if (myDt.Rows.Count > 0) { cription = myDt.Rows[0]["PUB_NAME"].ToString(); } string title = "这是动态生成的静态页面"; string dhtml = "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0 Transitional//CN\"><html><head>" + "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=gb2312\">" + "<title>" + title + "</title></head><body >"; dhtml += "<table >" + "<tr><td >" + title + "</td></tr><tr><td >" + cription + "</td></tr></table>" + "</body></html>"; string Filename = DateTime.Now.ToString("yyyyMMddHHmmss") + ".html";//动态的文件名 string Filepath = Server.MapPath(@"~/"); string Cname = DateTime.Now.Year.ToString() + DateTime.Now.Month.ToString(); string Filecreatepath = Filepath + Cname + @"/";//页面要保存的路径 //动态生成的静态页面按年月保存本年本月的文件夹中 if (Directory.Exists(Filecreatepath)) //判断当月的文件夹是否存在, { //调用创建html静态页面方法 Create_html(Filecreatepath + Filename, dhtml); } else { //创建页面保存到的文件夹 DirectoryInfo di = Directory.CreateDirectory(Filecreatepath); Create_html(Filecreatepath + Filename, dhtml); } } catch (IOException ex) { throw ex; } } private void Create_html(string allfilename, string htmlcode) { FileStream CreateFile = new FileStream(allfilename, FileMode.CreateNew); StreamWriter sw = new StreamWriter(CreateFile); sw.WriteLine(htmlcode);//将拼好的Html代码写入页面中 sw.Close(); Page.RegisterStartupScript("", "<script>window.alert('The file created successfully.!')</script>"); } 自我感觉用替换比较麻烦,有个方法直接可以找到静态代码,就类似“查看源代码”,然后直接将这些东西写到一个新html文件中。(仅供参考) 直接用ajax方法post当前页面到后台的某个专门处理评论的ashx来进行处理。 ASP.NET MVC用ADO.NET性能会差吗?都见人家用什么ORM之类的。 xp装完IIS以后为什么不能新建多个网站 面试时的一个很简单的问题但不知道怎么回答好 ASP.NET链接数据库 .net三层程序怎样进行多表联合操作? Contorls需要引用那个类?谢谢 求用vml读取sql server数据库生成线形图表的源代码! 怎样来引用WEB窗体当中的变量????? 请问任意点击DATAGRID触发什么事件 WPF的treeview控件跳转页面 ListView 控件如何增加 编辑,删除,更新按钮 关于ListBox绑定问题,
替换模板标签
生成静态页面
数据交互JS+AJAX
当然相关脚本与模板页一同生成。
直接 private void Page_Load(object sender, System.EventArgs e)
{
try
{
string cription = "";
myDt = cl.GetTable();//获取自己数据库中的一个table
if (myDt.Rows.Count > 0)
{
cription = myDt.Rows[0]["PUB_NAME"].ToString();
}
string title = "这是动态生成的静态页面";
string dhtml = "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0 Transitional//CN\"><html><head>" +
"<meta http-equiv=\"Content-Type\" content=\"text/html; charset=gb2312\">" +
"<title>" + title + "</title></head><body >";
dhtml += "<table >" +
"<tr><td >" + title + "</td></tr><tr><td >" + cription + "</td></tr></table>" +
"</body></html>";
string Filename = DateTime.Now.ToString("yyyyMMddHHmmss") + ".html";//动态的文件名
string Filepath = Server.MapPath(@"~/");
string Cname = DateTime.Now.Year.ToString() + DateTime.Now.Month.ToString();
string Filecreatepath = Filepath + Cname + @"/";//页面要保存的路径 //动态生成的静态页面按年月保存本年本月的文件夹中
if (Directory.Exists(Filecreatepath)) //判断当月的文件夹是否存在,
{
//调用创建html静态页面方法
Create_html(Filecreatepath + Filename, dhtml);
}
else
{
//创建页面保存到的文件夹
DirectoryInfo di = Directory.CreateDirectory(Filecreatepath);
Create_html(Filecreatepath + Filename, dhtml);
}
}
catch (IOException ex)
{
throw ex;
}
}
private void Create_html(string allfilename, string htmlcode)
{
FileStream CreateFile = new FileStream(allfilename, FileMode.CreateNew);
StreamWriter sw = new StreamWriter(CreateFile);
sw.WriteLine(htmlcode);//将拼好的Html代码写入页面中
sw.Close();
Page.RegisterStartupScript("", "<script>window.alert('The file created successfully.!')</script>");
}