The format of the existing dynamic page is similar to the pagename.aspx?id=1 format, and later, due to the publisher, the dynamic page is required to be converted to static HTML after uploading.
First, according to the format generated by the page, enumeration gets the page HTML:
1 foreach(varPageinchpagelist)2 {3 stringhtml = readhtml (string. Format ("pagename.aspx?id={0}", Page.id));4HTML =replacelistandsingle (HTML);5WriteHTML (string. Format ("pagename_{0}.html", page.id), HTML);6}
To read an ASP page:
Public Static stringReadhtml (stringsourceURL) { Try{System.Net.WebRequest myrequest=System.Net.WebRequest.Create (sourceURL); System.Net.WebResponse Myresponse=Myrequest.getresponse (); using(Stream stream =Myresponse.getresponsestream ()) { using(StreamReader sr =NewStreamReader (Stream, encoding.getencoding ("Utf-8"))) { returnSr. ReadToEnd (); } } } Catch(Exception ex) {Throw NewException (string. Format ("readhtml Error: {0}", ex. Message)); } }
Use a regular replacement for dynamic links within a page:
Public Static stringReplacelistandsingle (stringhtml) {HTML= Regex.Replace (HTML,@"_list\.aspx\?id= (\d*)","_list_$1.html", regexoptions.ignorecase); HTML= Regex.Replace (HTML,@"_single\.aspx\?id= (\d*)","_single_$1.html", regexoptions.ignorecase); returnHtml. Replace (". aspx",". html"); }
The dynamic page format is pagename_list.aspx?id=1 and pagename_single.aspx?id=1, and the regular replacement becomes a static format: Pagename_list_1.html and Pagename_single_1. Html.
Write the replaced page HTML to the file:
Public Static BOOLWriteHTML (stringUrlstringhtml) { Try { using(StreamWriter SW =NewStreamWriter (HttpContext.Current.Server.MapPath (URL),false, Encoding.GetEncoding ("Utf-8")) {sw. WriteLine (HTML); Sw. Close (); } return true; } Catch(Exception ex) {Throw NewException (string. Format ("writehtml error: {0}", ex. Message)); } }
ASP. NET generates static HTML based on existing dynamic page