Idea of generating static pages in Asp.net
1. Create an empty template page
2. Create An ASPX page to read the template information and replace the relevant information.
3. Write/htm to generate a new HTM
---------------------------------------------------------- Template --------------------------------------------------------
<! Doctype HTML public "-// W3C // dtd xhtml 1.0 transitional // en" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <HTML xmlns = "http://www.w3.org/1999/xhtml">
------------------------------------------------------------- Aspx -------------------------------------------------------------
Using system; using system. collections; using system. configuration; using system. componentmodel; using system. data; using system. drawing; using system. web; using system. web. sessionstate; using system. web. ui; using system. web. UI. webcontrols; using system. web. UI. htmlcontrols; using system. io; using system. text; using system. net; using system. data. sqlclient; public partial class test_excutehtml: system. web. UI. page {Protected void page_load (Object sender, eventargs e) {string SQL = string. empty; // string strname = session ["login_name"]. tostring (). trim (); string strdate = datetime. now. tostring ("mm DD, YYYY");/* string strtitle = string. empty; If (request. form ["titlez"]! = NULL) {strtitle = request. form ["titlez"]. tostring (). trim ();} string strcontent = string. empty; If (request. form ["bodyz"]! = NULL) {strcontent = request. form ["bodyz"]. tostring (). trim ();} string strclass = string. empty; If (request. form ["linoleic"]! = NULL) {strclass = request. form ["linoleic"]. tostring (). trim ();} */string strtitle = "my title"; string strclass = "I Am a category"; string strcontent = "I Am a content "; string strname = "name"; // enter the name based on the actual situation // encoding code = encoding. getencoding ("big5"); encoding code = encoding. getencoding ("gb2312"); streamreader sr = streamreader. NULL; streamwriter Sw = streamwriter. NULL; string STR = string. empty; // read the remote path string sessionpath = session ["path"]. tostring (). trim (); webrequest temp = webrequest. create (sessionpath + "template.htm"); webresponse mytemp = temp. getresponse (); Sr = new streamreader (mytemp. getresponsestream (), Code); // read try {sr = new streamreader (mytemp. getresponsestream (), Code); STR = sr. readtoend ();} catch (exception ex) {Throw ex;} finally {Sr. close ();} string filename = datetime. now. tostring ("yyyymmddhhmmss") + ". htm "; // file name // write try {Sw = new streamwriter (server. mappath ("htm/") + filename, false, Code); STR = Str. replace ("$ class {1} quot;, strclass); STR = Str. replace ("$ title {1} quot;, strtitle); STR = Str. replace ("$ content {1} quot;, strcontent); STR = Str. replace ("$ name {1} quot;, strname); STR = Str. replace ("$ Date {1} quot;, strdate); Sw. write (STR); Sw. flush ();} catch (exception ex) {Throw ex;} finally {SW. close (); strtitle = "<a href = .. /.. /form/g_it/news/htm/"+ filename +" target = _ blank> "+ strtitle +" </a> "; // SQL = "insert into [news1] (classz, titlez, namez, datez) values ('" + strclass + "', '" + strtitle + "', '"+ strname +"', '"+ strdate +"') "; // string CH = Nb. execsql (SQL ). tostring (). trim (); // CH = CH. tolower (); // response. write ("{success: True, CH:" + CH + "}");}}}