Currently, there are two methods to generate static pages. One is to directly access the dynamic page address and generate the htmlCodeSave as a static page. The other is to generate the content to be replaced by reading the page template. The previous method is simple. It is more practical to generate a single page or a small number of pages, and the first method is not convenient for a large number of pages that are associated with each other. The method for using templates is a little complicated. We will not discuss it in detail here. We will only provide the first method to deal with applications of less complex projects.
Then, all the link pages in index. aspx are static in sequence, so that the cycle is repeated.
The sample code below demonstrates how to replace the dynamic link address on the page with a static address named by the rule.
The following is a code snippet: Using system; Using system. Collections. Generic; Using system. Web; Using system. Web. UI; Using system. Web. UI. webcontrols; Using system. Text. regularexpressions; Namespace webtest { Public partial class test: system. Web. UI. Page { Protected void page_load (Object sender, eventargs E) { String content = "<a target = \" _ blank \ "href = \" product. aspx? Classid = 123 \ "> <a target = \" _ blank \ "href = \" Product-view.aspx \ "> <a target = \" _ blank \ "href = \" Product-view.aspx? Id = 59 \ "> <a target = \" _ blank \ "href = \" Product-view.aspx? Id = 11159 \ "> "; String newcontent = content; RegEx Rg = new RegEx ("href ="); // locate the link using the regular expression Int Len = 5; // regular character Length Matchcollection MC = RG. Matches (content ); Foreach (Match m in MC) { Int startindex = M. index + Len + 1; // the starting position of the located URL Int endindex = content. indexof ("\" ", M. index + Len + 1); // locate the end position of the URL String originalurl = content. substring (startindex, endindex-startindex); // obtain the full URL String newurl = ""; Newurl = originalurl. Replace (". aspx? Classid = ","-class-"); // Replace the product type Newurl = newurl. Replace (". aspx? Id = ","-"); // Replace the product Newurl = newurl. Replace (". aspx ",""); Newurl + = ". html "; Newcontent = newcontent. Replace (originalurl + "\" ", newurl +" \ ""); // replace the original URL with a static address. } Response. write (string. format ("original content: {0} <br/> new content: {1}", content. replace ("<", "& lt ;"). replace (">", "& gt;"), newcontent. replace ("<", "& lt ;"). replace (">", "& gt ;"))); } } } |
The running result of this page is as follows:
The following is a code snippet: Original content: <a target = "_ blank" href = "product. aspx? Classid = 123 "> <a target =" _ blank "href =" Product-view.aspx "> <a target =" _ blank "href =" Product-view.aspx? Id = 59 "> <a target =" _ blank "href =" Product-view.aspx? Id = 11159 "> New content: <a target = "_ blank" href = "Product-class-123.html"> <a target = "_ blank" href = "Product-view.html"> <a target = "_ blank" href = "Product-view-59.html "> <a target =" _ blank "href =" Product-view-11159.html "> |
Sterilization pouch Shanghai registered company