protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
getUrltoHtml("Default2.aspx", Server.MapPath("~") + "\\index.html");
}
}
#region//生成被请求URL静态页面
public void getUrltoHtml(string Url, string Path)//Url为动态页面地址,Path为生成的静态页面
{
try
{
System.Net.WebRequest wReq = System.Net.WebRequest.Create(Url);
//ex = {"无效的 URI: 无法确定 URI 的格式。"}
// Get the response instance.
System.Net.WebResponse wResp = wReq.GetResponse();
// Get the response stream.
System.IO.Stream respStream = wResp.GetResponseStream();
// Dim reader As StreamReader = New StreamReader(respStream)
System.IO.StreamReader reader = new System.IO.StreamReader(respStream, System.Text.Encoding.GetEncoding("utf-8"));
string str = reader.ReadToEnd();
System.IO.StreamWriter sw = new System.IO.StreamWriter(Path, false, System.Text.Encoding.GetEncoding("utf-8"));
sw.Write(str);
sw.Flush();
sw.Close();
System.Web.HttpContext.Current.Response.Write("<script>alert('页面生成成功!');</script>");
}
catch (System.Exception ex)
{
System.Web.HttpContext.Current.Response.Write("<script>alert('页面生成失败!" + ex.Message + "');</script>");
}
}
#endregion
//ex = {"无效的 URI: 无法确定 URI 的格式。"}
这里啊