技术开发 频道

生成静态页面加速访问


【IT168技术文档】

  BasePage继承System.Web.UI.Page, 重载OnInit()和Render().
protected override void OnInit(EventArgs e) { //If the request page do not contains the module id, assign the default value it first. if (String.IsNullOrEmpty(Request[MODULE_ID_KEY])) { Response.Redirect(Request.Url.OriginalString + "?ModuleId=1"); } if (File.Exists(StaticHtml)) { Response.Redirect(VHtml); } Literal coding = new Literal(); //The following 2 lines are specific for my project. coding.Text = "<meta http-equiv='Content-Type' content='text/html;charset=utf-8'>"; this.Controls.AddAt(0, coding); base.OnInit(e); } protected override void Render(HtmlTextWriter writer) { StreamWriter sw = File.CreateText(StaticHtml); HtmlTextWriter hw = new HtmlTextWriter(sw); base.Render(hw); hw.Flush(); sw.Flush(); hw.Close(); sw.Close(); Response.Redirect(VHtml); }
0
相关文章