Introduction to the idea of generating static pages using ASP. NET

Source: Internet
Author: User

Today, we will study the generation of static pages and record the learning content as follows.

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.

 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 regular expression to the link
Int Len = 5 ; // Regular character Length
Matchcollection MC = RG. Matches (content );
Foreach (Match m In MC)
{
Int Startindex = M. Index + Len + 1 ; // Start position of the URL to be located
Int Endindex = Content. indexof ( " \" " , M. Index + Len + 1 ); // The end position of the URL to be located
String Originalurl = Content. substring (startindex, endindex - Startindex ); // Obtain the full URL
String Newurl = "" ;
Newurl = Originalurl. Replace ( " . Aspx? Classid = " , " -Class- " ); // Product Type replacement
Newurl = Newurl. Replace ( " . Aspx? Id = " , " - " ); // Product replacement
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:

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 ">

The above is just a bit of thought, and more content is to be studied.

Related Article

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.