Use ASP. NET to generate static pages

Source: Internet
Author: User

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:

Sterilization pouch Shanghai registered company
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 ">

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.