One is to directly access the dynamic page address and save the generated html code 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. Bytes
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 ;")));
}
}
}