asp.net获取当前页面源码并生成静态页面
StringWriter stringWriter = new StringWriter(); HtmlTextWriter htmlWriter = new HtmlTextWriter(stringWriter); this.Page.RenderControl(htmlWriter); string html = stringWriter.GetStringBuilder().ToString(); string path = HttpContext.Current.Server.MapPath("~/cache/index.htm"); File.WriteAllText(path, html, System.Text.Encoding.Default);
//成功一定有方法,失败一定有原因。