. NET quick way to generate static Web pages

Source: Internet
Author: User

In general, there are two ways to generate a static web page using. NET, usually through the browser to trigger the dynamic. aspx file to parse the Web page, and then generate the Web page, this method we do not (because this method needs to waste relatively large server performance, and the speed is relatively slow, a second can only generate about 10 pages), so we are going The second method, write a Web page template, and then use. NET to parse the tag, and then to complete this generation of Web page static function (exclusive network (http://www.sz886.com)-Shenzhen website Construction-http:// www.sz886.com Technician Test 1 seconds can generate more than 100 Web pages, the performance is very good and stable, if you turn on multi-threaded, the user experience is very good. )
?
First of all, we generate Web pages need to use the technology to have I/O stream file read and write, and then we use the regular expression to parse the label, at most we use multithreading to ensure stability and speed.

First we create a called duzhan.html (master file), and a top.html (header file)
We write the message in the header file as follows:
This is the head file of the Web page, the head file originated from Shenzhen Exclusive Network Technology Co., Ltd. (http://www.sz886.com)
And then we write the code for the duzhan.html (main file) is
<!doctype html>
This is the header file to parse, just above the top.html file we wrote
<!--include file= "top.html"/-->
This is a cyclic parsing tag, we'll use it here, we'll write it here first.
<!--list table= "1" typeid= "1" num= "where=" 1=1 "order=" SortID asc,id ASC "-
This is the label of a judgment, we are here to write first here, the following will talk about
<!--if testbase= "@[email protected]" testvalue= "1" testmodel= "="-
<li><a href= "@[email protected]" ></a ></li>
<!--else-->
<li><a href= "@[email protected]" ></a></li>
<!--/if-->
<!--/list-->
</body>
Now we have two pages of the template is written, and then we are to parse the label we write, and then to generate it.
First, we build a CreateFile.cs file to place the read-write file method.
This is a new static page information to create, Newsstrwebinfo is an incoming parameter (used to replace the original information)
public static string Createsinglefile (String strmodefilepath)
{
Create a file stream that reads the file information
StreamReader strreader = null;
Find out the path of the module file in the server, there is no server.mappath, there will be problems in multi-threading
String FilePath = System.IO.Path.Combine (AppDomain.CurrentDomain.BaseDirectory) + Strmodefilepath;
How to get a message numbered Utf-8
Encoding code = encoding.getencoding ("Utf-8");
Create a Strallinfo string to hold the information we read
String strallinfo = String. Empty;
Try
{
Get a read file stream with a file path of filepath, encoded as code
Strreader = new StreamReader (FilePath, code);
Read all the information in the file stream and store it in Strallinfo.
Strallinfo = Strreader.readtoend ();
}
catch (Exception ex)
{
Throw ex;
} finally
{//close Read file stream
Strreader.close ();
}
return strallinfo;
}
Then we'll write one more method.
public bool Createwritefile (string Strnewsfilepath, String strfileinfo)
{
BOOL flag = FALSE;
Create a file stream that writes file information
StreamWriter strwrite = null;
How to get a message numbered Utf-8
Encoding code = encoding.getencoding ("Utf-8");
Try
{//Create a write file stream
Strwrite = new StreamWriter (System.IO.Path.Combine (AppDomain.CurrentDomain.BaseDirectory) + Strnewsfilepath, False, code);
Write the information you just learned into the file stream.
Strwrite.write (strFileInfo);
Create success is True
Flag = true;
}catch (Exception ex)
{
Throw ex;
} finally
{Strwrite.flush ();
Close file stream
Strwrite.close ();
}
return flag;
}
The above defines the read template and the method of generating the template, and then we will create a method to parse the tag.
We'll build a DuZhanTag.cs file.
We build a way to generate Web pages
public void Createdefault (string htmlpath, string filename)
{
Write the duzhan.html file path we just wrote and read the information
String html = Createfile.createsinglefile (Htmlpath);
If the read information is not read to the information we will return back.
if (string. IsNullOrEmpty (HTML))
{return;}
To parse our tags, this method is defined below.
Html=createincludehtml (Strallinfo);
Generating files
New CreateFile (). Createwritefile (filename, HTML);
}

Because the page is not fit, we write the following method in. NET quick Build static Web page method two http://www.sz886.com/zhishi/112110.html

. NET quick way to generate static Web pages

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.