页面中 动态内容静态化。 那位高手能解释下。。 小弟初来乍到,需求各位大哥的帮助。。 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 urlrewriter 伪静态静态页面protected override void Render(HtmlTextWriter writer) { StreamWriter r=new StreamWriter(Server.MapPath(""), false,System.Text.Encoding.UTF8); HtmlTextWriter h=new HtmlTextWriter(r); base.Render(h); r.Close(); h.Close(); } StringWriter wr = new StringWriter(); Server.Execute("", wr); this.lit.Text = Server.HtmlEncode(wr.ToString()); File.WriteAllText(Server.MapPath(""), wr.ToString()); 生成静态页: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 asp.net生成静态页面 File.Copy()无法把文件从一个共享的服务器地址拷贝到本地 如何把标记了【Serializable】的类序列化成XML? 并且在WCF的服务的参数中传递? jmail组件 用 exchange 发送邮件失败 怎样加载用户控件的问题????????? Javascript的一个取值问题!! 如何用程序修改某个资源文件中的值 [高手指教]一个比较棘手的问题! C#中的new会不会在内存中分配内存? 求一些函数? DataSet查询数据速度问题 iframe跨域问题 窗体是不是控件。。
静态页面
protected override void Render(HtmlTextWriter writer) {
StreamWriter r=new StreamWriter(Server.MapPath(""), false,System.Text.Encoding.UTF8);
HtmlTextWriter h=new HtmlTextWriter(r);
base.Render(h);
r.Close();
h.Close();
}
StringWriter wr = new StringWriter();
Server.Execute("", wr);
this.lit.Text = Server.HtmlEncode(wr.ToString());
File.WriteAllText(Server.MapPath(""), wr.ToString());
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