分页 静态化怎么做啊

vvv6965921vvv 2010-09-10 07:22:54
我的分页是用asp.ent pager控件做的 怎么让他生成静态网站啊
...全文
125 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
zhangaijiang 2010-09-12
  • 打赏
  • 举报
回复
重写url 用urlrewrite插件

UrlRewritePattern="./News-PageIndex{0}.html"
<LookFor>~/News-PageIndex(\d{0,10})\.html</LookFor>
<SendTo>~/News.aspx?page=$1</SendTo>


重写url详解
jianshao810 2010-09-12
  • 打赏
  • 举报
回复
url 静态吗?
重写url吧。用urlrewrite插件
vvv6965921vvv 2010-09-12
  • 打赏
  • 举报
回复
生成HTML我知道 问题是怎么重定向啊 万一生成的HTML的名字叫 3.html 那我重定向这里怎么写呢 难道预先就知道3.html??
porschev 2010-09-12
  • 打赏
  • 举报
回复

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net;
using System.IO;
using System.Threading;




private Thread thr;

public Thread Thr
{
get
{
if (System.Web.HttpContext.Current.Application["thread"] == null)
return null;
else
return (Thread)System.Web.HttpContext.Current.Application["thread"];
}
set
{
System.Web.HttpContext.Current.Application["thread"] = value;
}
}

public CreateHTML() { }

/// <summary>
/// 生成静态页
/// </summary>
/// <param name="reqpath">请求地址</param>
/// <param name="savepath">生成路径</param>
public CreateHTML(string reqpath, string savepath)
{
if (thr == null)
{
ThreadStart starter = delegate { GenerateHtml(reqpath, savepath); };
Thread th = new Thread(starter);
th.IsBackground = false;
thr = th;
thr.Start();
}
else
{
if (thr.ThreadState.Equals(ThreadState.Aborted))
Thread.ResetAbort();
}
}

/// <summary>
/// 批量生成
/// </summary>
/// <param name="dic">key是生成地址,value是请求地址</param>
public CreateHTML(Dictionary<string,string> dic)
{
if (thr == null)
{
ThreadStart starter = delegate { GenerateHtml(dic); };
Thread th = new Thread(starter);
th.IsBackground = false;
thr = th;
thr.Start();
}
else
{
if (thr.ThreadState.Equals(ThreadState.Aborted))
Thread.ResetAbort();
}
}




#region 生成静态页

/// <summary>
/// 生成静态页
/// </summary>
/// <param name="reqpath">请求地址</param>
/// <param name="savepath">生成地址</param>
public bool BulidHtml(string reqpath, string savepath)
{
bool reslut = false;
try
{
WebRequest wr = WebRequest.Create(reqpath);
WebResponse wrs = wr.GetResponse();
Stream str = wrs.GetResponseStream();
StreamReader sr = new StreamReader(str, System.Text.Encoding.GetEncoding("utf-8"));
string abc = sr.ReadToEnd();

StreamWriter sw = null;

string path = savepath.Replace("/", @"\");

int pos = path.LastIndexOf(@"\");
if (pos != -1)
{
string dir = path.Substring(0, pos);
if (!Directory.Exists(dir))
{
Directory.CreateDirectory(dir);
}
try
{
sw = new StreamWriter(path, false, System.Text.Encoding.GetEncoding("utf-8"));
sw.Write(abc);
reslut = true;
}
catch (Exception ex)
{
//throw new Exception("出错啦:" + ex.Message);
}
finally
{
wrs.Close();
str.Close();
str.Flush();
sr.Close();
sw.Flush();
sw.Close();
}
}
return reslut;
}
catch (Exception)
{

return reslut;
}

}


/// <summary>
/// 生成静态页
/// </summary>
/// <param name="reqpath">请求地址</param>
/// <param name="savepath">生成地址</param>
private void GenerateHtml(string reqpath, string savepath)
{
WebRequest wr = WebRequest.Create(reqpath);
WebResponse wrs = wr.GetResponse();
Stream str = wrs.GetResponseStream();
StreamReader sr = new StreamReader(str, System.Text.Encoding.GetEncoding("utf-8"));
string abc = sr.ReadToEnd();

StreamWriter sw = null;

string path = savepath.Replace("/", @"\");

int pos = path.LastIndexOf(@"\");
if (pos != -1)
{
string dir = path.Substring(0, pos);
if (!Directory.Exists(dir))
{
Directory.CreateDirectory(dir);
}
try
{
sw = new StreamWriter(path, false, System.Text.Encoding.GetEncoding("utf-8"));
sw.Write(abc);
}
catch (Exception ex)
{
//todo:此处单独做错误处理
}
finally
{
wrs.Close();
str.Close();
str.Flush();
sr.Close();
sw.Flush();
sw.Close();
thr.Abort();
}
}
}

/// <summary>
/// 批量生成静态页
/// </summary>
/// <param name="dic">key是生成地址,value是请求地址</param>
private void GenerateHtml(Dictionary<string,string> dic)
{

foreach (string savepath in dic.Keys)
{
string reqpath = dic[savepath];
WebRequest wr = WebRequest.Create(reqpath);
WebResponse wrs = wr.GetResponse();
Stream str = wrs.GetResponseStream();
StreamReader sr = new StreamReader(str, System.Text.Encoding.GetEncoding("utf-8"));
string abc = sr.ReadToEnd();

StreamWriter sw = null;

string path = savepath.Replace("/", @"\");

int pos = path.LastIndexOf(@"\");
if (pos != -1)
{
string dir = path.Substring(0, pos);
if (!Directory.Exists(dir))
{
Directory.CreateDirectory(dir);
}
try
{
sw = new StreamWriter(path, false, System.Text.Encoding.GetEncoding("utf-8"));
sw.Write(abc);
}
catch (Exception ex)
{
//todo:此处单独做错误处理
}
finally
{
wrs.Close();
str.Close();
str.Flush();
sr.Close();
sw.Flush();
sw.Close();
}
}
}
thr.Abort();
}
#endregion




wuyq11 2010-09-10
  • 打赏
  • 举报
回复
PageSize="10" EnableUrlRewriting="true"
UrlRewritePattern="./News-PageIndex{0}.html"
<LookFor>~/News-PageIndex(\d{0,10})\.html</LookFor>
<SendTo>~/News.aspx?page=$1</SendTo>
hackerdream 2010-09-10
  • 打赏
  • 举报
回复
动态的怎么做? 一个思路,比如 http://***.com/aaaa.aspx?page=1 后面的page 是页数,
然后设置一个读取页面,输出HTML 的类,你想要第几页的静态,就直接通过这个类传参数,生成就可以了。。。

做过类似的东西

111,129

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Creator Browser
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

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