Asp.net will generate static pages directly on dynamic pages (garbled)

Source: Internet
Author: User

Recently, I am working on some static pages for a website to directly generate static pages for some dynamic pages.

 

We have long known that this can be implemented using WebClient, which can be used to remotely read dynamic pages.

 

Then write the read content to the corresponding static file. To put it bluntly, there are two actions: read and write.

 

However, during reading and writing, you must ensure that the encoding is consistent. Otherwise, the content may be garbled or the webpage may be garbled.

I also read the solution for solving static pages on the Internet.

Today, I will share my simplest method with you. Maybe the experts think this is too simple, too common, and there is no need to send it.

However, the content I wrote is relatively simple and cannot be written in depth, so I wrote it to my friends who have such troubles.

Friends who can generate a common solution or have a simpler solution remember to reply to the message.

 

 

Code

1 private void makehtml (string URL, string SaveFile)
2 {
3 WebClient WC = new WebClient ();
4 byte [] BS = WC. downloaddata (URL );
5 string html = encoding. getencoding ("gb2312"). getstring (BS );
6 string SaveFile = server. mappath (SaveFile );
7 streamwriter Sw = new streamwriter (SaveFile, false, encoding. getencoding ("gb2312 "));
8 SW. Write (HTML );
9 Sw. Close ();
10}

 

 

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.