aspx转成htm
protected override void Render(HtmlTextWriter writer)
{
StringWriter html=new StringWriter();
HtmlTextWriter htw = new HtmlTextWriter(html);
base.Render(htw);
StreamWriter streamwriter = new StreamWriter(this.Server.MapPath( "Default.htm "), false, System.Text.Encoding.Default);
streamwriter.Write(html.ToString());
htw.Close();
streamwriter.Close();
this.Response.Redirect( "Default.htm ");
}
我用上述方法将aspx转成htm,但这样做,必须在每个页面中都写一个这样的函数,有什么方法可以只写一次这种函数但可以实现每个页面都转成htm吗?
------解决方案--------------------public class yourPage: System.Web.Ui.Page
{
protected override void Render(HtmlTextWriter writer)
{
StringWriter html=new StringWriter();
HtmlTextWriter htw = new HtmlTextWriter(html);
base.Render(htw);
StreamWriter streamwriter = new StreamWriter(this.Server.MapPath( "Default.htm "), false, System.Text.Encoding.Default);
streamwriter.Write(html.ToString());
htw.Close();
streamwriter.Close();
this.Response.Redirect( "Default.htm ");
}
}
然后将你的页面的codebehind代码中的父类由 Page 改为 yourPage。对于没有codebehind 代码的aspx,设置其 <%@ Page> 的inherits属性。