都要走了,告诉我首页速度慢--!,那我静态一下吧...
代码
/// <summary>
/// 生成静态页
/// </summary>
public class CreateHTML
{
/// <summary>
/// 生成静态页
/// </summary>
/// <param name="UrlAdd">要生成的页面</param>
/// <param name="Saveadd">保存的地址</param>
/// <param name="Name">文件名称</param>
/// <param name="EncodingCode">编码</param>
public static int StatePage(string UrlAdd, string Saveadd, string Name, string EncodingCode)
{
try
{
System.Net.WebRequest HttpWebRequest = System.Net.WebRequest.Create(UrlAdd);
System.Net.WebResponse HttpWebResponse = HttpWebRequest.GetResponse();
System.IO.StreamReader sr = new System.IO.StreamReader(HttpWebResponse.GetResponseStream(), System.Text.Encoding.GetEncoding(EncodingCode));
string FileName = Name + ".html";
string ffname = System.Web.HttpContext.Current.Server.MapPath(Saveadd) + FileName;
string txthtm = sr.ReadToEnd();
FileInfo finfo = new FileInfo(ffname);
using (FileStream fs = finfo.OpenWrite())
{
StreamWriter sw = new StreamWriter(fs, System.Text.Encoding.GetEncoding("GB2312"));
sw.WriteLine(txthtm);
sw.Flush();
sw.Close();
}
return 1;
}
catch
{
return -1;
}
}
}
/// 生成静态页
/// </summary>
public class CreateHTML
{
/// <summary>
/// 生成静态页
/// </summary>
/// <param name="UrlAdd">要生成的页面</param>
/// <param name="Saveadd">保存的地址</param>
/// <param name="Name">文件名称</param>
/// <param name="EncodingCode">编码</param>
public static int StatePage(string UrlAdd, string Saveadd, string Name, string EncodingCode)
{
try
{
System.Net.WebRequest HttpWebRequest = System.Net.WebRequest.Create(UrlAdd);
System.Net.WebResponse HttpWebResponse = HttpWebRequest.GetResponse();
System.IO.StreamReader sr = new System.IO.StreamReader(HttpWebResponse.GetResponseStream(), System.Text.Encoding.GetEncoding(EncodingCode));
string FileName = Name + ".html";
string ffname = System.Web.HttpContext.Current.Server.MapPath(Saveadd) + FileName;
string txthtm = sr.ReadToEnd();
FileInfo finfo = new FileInfo(ffname);
using (FileStream fs = finfo.OpenWrite())
{
StreamWriter sw = new StreamWriter(fs, System.Text.Encoding.GetEncoding("GB2312"));
sw.WriteLine(txthtm);
sw.Flush();
sw.Close();
}
return 1;
}
catch
{
return -1;
}
}
}