请想挑战的大侠来看看,关于asp.net生成html
网站找的,生成代码如下:
每个aspx页面都有类似如index.aspx的代码
//生成静态页面
protected override void Render(HtmlTextWriter writer)
{
System.IO.StringWriter html = new System.IO.StringWriter();
System.Web.UI.HtmlTextWriter tw = new HtmlTextWriter(html);
base.Render(tw);
System.IO.StreamWriter sw = new System.IO.StreamWriter(Server.MapPath("index.html"), false, System.Text.Encoding.Default);
sw.Write(html.ToString());
sw.Close();
tw.Close();
Response.Redirect("index.html");
}
运行后,分页也正常,
index.aspx页面有好几个用户控件,
点击这些用户控件的链接,比如 联想公司
应该转到 联想公司的详细页面的:在一表格显示联想公司的各种信息,
但弹出的页面却只有空白表格,没有内容,
哪位助我呀,非常感谢!
网站找的,生成代码如下:
每个aspx页面都有类似如index.aspx的代码
//生成静态页面
protected override void Render(HtmlTextWriter writer)
{
System.IO.StringWriter html = new System.IO.StringWriter();
System.Web.UI.HtmlTextWriter tw = new HtmlTextWriter(html);
base.Render(tw);
System.IO.StreamWriter sw = new System.IO.StreamWriter(Server.MapPath("index.html"), false, System.Text.Encoding.Default);
sw.Write(html.ToString());
sw.Close();
tw.Close();
Response.Redirect("index.html");
}
运行后,分页也正常,
index.aspx页面有好几个用户控件,
点击这些用户控件的链接,比如 联想公司
应该转到 联想公司的详细页面的:在一表格显示联想公司的各种信息,
但弹出的页面却只有空白表格,没有内容,
哪位助我呀,非常感谢!
就是我在网上找了一大把,没有一个方案能解决我的问题,你要是有,能否给我一分,或者一个完整的思路也行,网上找的都宣称能生成HTML,但都有这样那样的问题啊,[email protected]
{
try
{
WebClient MyWebClient = new WebClient(); MyWebClient.Credentials = CredentialCache.DefaultCredentials;//获取或设置用于对向Internet资源的请求进行身份验证的网络凭据。 Byte[] pageData = MyWebClient.DownloadData("http://www.jjxcf.com/home/index.aspx");//从指定网站下载数据
string pageHtml = Encoding.GetEncoding("GB2312").GetString(pageData);
// string pageHtml = Encoding.Default.GetString(pageData); //如果获取网站页面采用的是GB2312,则使用这句
// lb_1.Text = pageHtml; // string pageHtml = Encoding.UTF8.GetString(pageData); //如果获取网站页面采用的是UTF-8,则使用这句 // Console.WriteLine(pageHtml);//在控制台输入获取的内容 string temppath = HttpContext.Current.Server.MapPath(".") + "/../index.html";
using (StreamWriter sw = new StreamWriter(temppath, false, Encoding.GetEncoding("GB2312")))//将获取的内容写入文本
{
sw.Write(pageHtml);
Function.Script.Alert("已成功生成首页");
// Response.Write("OK");
} //Console.ReadLine(); //让控制台暂停,否则一闪而过了
} catch (WebException webEx)
{
Response.Write(webEx.Message.ToString());
//Console.WriteLine(webEx.Message.ToString());
}
}