ASP.NET dynamically generate HTML pages

xiaoxiao2021-03-17  200

Think

1. Use tools such as DW-MX to generate a template of the HTML format, add special tags (such as $ HTMLFORMAT $) where you need to add formats, dynamically generate files to read this template when you use the code, then get the contents of the front desk, Add to this template's tag position, generate a new file name and write the disk, and write related data to the database after writing.

2. Use the background code hard to encode the HTML file, you can use the HTMLTextWriter class to write the HTML file.

advantage

1. You can create a very complex page, using methods containing JS files, join the document.write () method in the JS file can be added to all pages, advertising, etc.

2. Static HTML file Use the MS Windows2000 index server to establish a full-text search engine, using the ASP

.NET can get search results in a DataTable method. The Win2000's INDEX service cannot find the content of the XML file. This search feature will be very powerful if the database search is included with the INDEX index.

3. Save the server's load, request a static HTML file to save a lot than an ASPX file server resource.

Disadvantage

Idea 2: If you use hard-coded way, the workload is very large, you need a lot of HTML code. Difficulties in debugging. Moreover, the HTML style generated by hardcod cannot be modified. If the site is replaced, then you must re-encode, bringing huge effort to the later period.

So this is the first idea

Library code

1. Define (Template.htm) HTML Template Page

<

HTML

>

<

HEAD

>

<

Title

>

Title

>

<

Meta

HTTP-Equiv

= "Content-Type"

Content

= "text / html; charSet = GB2312"

>

HEAD

>

<

Body

>

<

TABLE

$ htmlformat [0] Height

= "100%"

Border

= "0"

Width

= "100%"

Cellpadding

= "10"

Cellspacing

= "0"

Bgcolor

= "# eeeeee"

Style

= "Border: 1px solid # 000000"

>

<

TR

>

<

TD

Width

= "100%"

Valign

= "middle"

Align

= "Left"

>

<

Span

Style

= "Color: $ htmlformat [1]; font-size: $ htmlformat [2]"

>

$ HTMLFORMAT [3]

Span

>

TD

>

TR

>

TABLE

>

Body

>

HTML

>

2.asp

.NET code:

// ---------------------

Read the HTML template page to the StringBuilder object

----

String

[]

Format

=

New

String

[

4

];

//

Array StringBuilder HTMLText, unintended and HTMLYEM tag

=

New

Stringbuilder (); try

{Using (StreamReader SR

=

New

StreamReader

"

Store template pages path and page name

"

)) {

String

Line;

While

((LINE)

=

sr.readline ())!

=

NULL) {htmltext.append (line);} sr.close ();}}

Catch

{Response.

Write

(

"