关于aspx网站转静态页面
来源:互联网 发布:淘宝ipad货源 编辑:程序博客网 时间:2024/06/04 23:21
一直觉得百度蜘蛛对于?比较感冒,而且一个网站aspx页面也够少的,所以就想把aspx转成静态也面 经过查资料终于完成了,留点资料做备注。
首先思路是在后台点击“生成静态页面” 转换为静态页面
protected void Button2_Click(object sender, EventArgs e)
{
DataSet ds = Getyuqian().GetList(0, "", "Tdate desc");//取列表数据
string str="";
if (ds != null && ds.Tables[0].Rows.Count > 0)
{
for (int i=0; i < ds.Tables[0].Rows.Count-1; i++)//循环ID
{
str = ds.Tables[0].Rows[i]["id"].ToString();
System.IO.StringWriter swHtml = new System.IO.StringWriter();
Server.Execute("../../yuqiand.aspx?id="+str, swHtml);//获取该数据生成页面的html
String file1 = str.Substring(0,5)+".html";//去ID前5位为页面名字,因为我把ID加密了比较长
string contentStr = swHtml.ToString();
string filePath = Server.MapPath("/");//获取网站本地的基目录
if (!System.IO.Directory.Exists(filePath))
{
System.IO.Directory.CreateDirectory(filePath);
}
//如果存在该页面就删除
foreach (string file in System.IO.Directory.GetFiles(filePath))
{
if (file.Substring(file.Length-10,10) == file1)
{
File.Delete(file);
}
}
filePath += file1;
//按UTF-8导入,不然乱码
System.IO.StreamWriter sWrite = new System.IO.StreamWriter(filePath, true, Encoding.GetEncoding("UTF-8"));
sWrite.Write(contentStr);
sWrite.Flush();
sWrite.Close();
}
}
}
后来我想,添加数据和修改数据就自动生成页面了,那么,使用次数就比较多就些个类来调用把
调用页面:
Boolean boolx = false;
Helper.Tohtml htmlto = new Helper.Tohtml();
boolx = htmlto.writehtml("../../zyd.aspx?id=", model.id.ToString());
if (boolx == true)
{
// AlertResponse("发布成功!", "list_qy.aspx");
}
类:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;
using System.IO;
using System.Text;
using System.ComponentModel;
namespace Helper
{
/// <summary>
///html 的摘要说明
/// </summary>
public class Tohtml
{
public Boolean writehtml(string url,string str)
{
System.IO.StringWriter swHtml = new System.IO.StringWriter();
HttpContext.Current.Server.Execute(url + str, swHtml);
// System.Web.HttpUtility.HtmlEncode(url + str);
String file1 = str.Substring(0, 5) + ".html";
string contentStr = swHtml.ToString();
//string filePath = Server.MapPath("/");
string filePath = HttpContext.Current.Server.MapPath("/");
if (!System.IO.Directory.Exists(filePath))
{
System.IO.Directory.CreateDirectory(filePath);
}
//如果存在该页面就删除
foreach (string file in System.IO.Directory.GetFiles(filePath))
{
if (file.Substring(file.Length - 10, 10) == file1)
{
File.Delete(file);
}
}
filePath += file1;
System.IO.StreamWriter sWrite = new System.IO.StreamWriter(filePath, true, Encoding.GetEncoding("UTF-8"));
sWrite.Write(contentStr);
sWrite.Flush();
sWrite.Close();
return true;
}
}
}
OK,可以调用了,除了自己更改就不用点生成就OK了
- 关于aspx网站转静态页面
- Aspx页面转静态页面
- 实现ASPX页面动态转静态
- aspx生成静态页面
- aspx页面静态化
- 关于post一个aspx页面
- 关于aspx文件生成静态页面问题与我的回答
- 用aspx生成静态页面的办法
- 将指定的aspx页面静态化
- aspx页面转html
- 网站生成静态页面
- 网站页面静态化
- 把动态页面.aspx 生成静态页面.html
- 动态.aspx页面生成静态.html页面 学习总结
- 关于aspx页面输出的总结
- 关于网站静态化
- 关于静态页面
- 关于页面静态化
- 关于viewpager的getChildAt()方法的错误使用
- 主机与namespace建立通信
- AD转换器选用原则
- 利用位运算实现加、减、乘、除
- Effective C++——条款32(第6章)
- 关于aspx网站转静态页面
- iOS 数据持久化-----plist
- Verilog HDL语法基础
- 内核ASoC之path
- java计时
- iOS中正确的截屏姿势
- erl_线性结构-折半查找
- N宫格之横竖斜的和都相等
- Android webview 使用自定义自体