我用。net做了个新闻发布系统,请问如何把这个做成静态页啊?

解决方案 »

  1.   

    从写Render(HtmlTextWriter hw) 这个方法。
      

  2.   

    url 重写,不过这个只是改变一下后缀名称,网页还是动态的生成纯静态的页面就用模版,替换,写成html文件
      

  3.   

    就是先做一个模板,把要放内容的地方先用一个字符比如:$title$占个位置,然后使用streamreader和Streamwriter进行操作,
    先读取模板页中的内容并保存在一个string变量中,然后进行替换,把刚前面说的那些占位字符替换成你的想要的内容,最后进行写文件操作保存文件(后缀为.html的)
      

  4.   

    我做过新闻发布的静态页面,这是一部分代码,不知道对你有没有帮助。
            private void newspage()
            {
                string[,] list = new string[,]{
                    {"financialtimes", "Financial Times"},
                    {"bbcnews", "BBC News"},
                    {"cepnews", "CEP News"},
                    {"actionforex", "ActionForex.com"},
                    {"fxstreet", "FX Street"},
                    {"fx360", "FX360.com"},
                    {"dailyfx", "Daily FX"},
                    {"moreover", "Moreover"},
                };            int n = list.GetLength(0);
                StringBuilder body = new StringBuilder(5000);
                string str;
                string path = System.AppDomain.CurrentDomain.BaseDirectory + "news/news2.htm"; //取网站虚拟目录的实际文件夹
                using (StreamReader sr = File.OpenText(path))
                {
                    str = sr.ReadToEnd();
                    for (int i = 0; i < n; i++)
                    {
                        body.Remove(0, body.Length);
                        DataRow[] rows = dtNews.Select("publisher='" + list[i, 1] + "'", "tim DESC");
                        int m = rows.GetLength(0);
                        for (int j = 0; j < m; j++)
                        {
                            DataRow row = rows[j];
                            body.AppendFormat("<div class='nstyle1'>" +
                                "<div class='nstyle2'>{0:yyMMdd HHmmss}</div> <a href=\"javascript:showdescriptionl('id{6}_{5}')\">{1}</a></div>" +
                                "<div id='id{6}_{5}' class='style100'><br><a class='s14' href='../LinkOut.htm?FROM=homepage&URL={2}' target='_blank'>STORY LINK</a> <span class='s14 red'>{4}</span><br><br>{3}</div>",
                                row[1], row[2], row[3], Components.comm.txtTOhtm(row[4].ToString()), row[0], j, i
                                );
                        }
                        str = str.Replace("<hhhh:" + list[i, 0] + " />", body.ToString());
                    }
                }
                path = System.AppDomain.CurrentDomain.BaseDirectory + "news/news.htm"; //取网站虚拟目录的实际文件夹
                using (StreamWriter sw = File.CreateText(path)) //?? 能不能打开一次文件,完成读和写。 
                {
                    sw.Write(str);
                }
            }
      

  5.   

    模版的I/0量和replace计算量过大,
    伪静态的也没有什么意义,
    比较合理的方法是用ajax+ashx,前台是正真的html,不过目前不太成熟,例子也不多。