ASP. NET templates generate HTML pages

Source: Internet
Author: User

A while ago, a buddy asked me how to generate HTML static pages from a template?

First, generate HTML benefits

    1. HTML is static, needless to say, the speed is certainly faster (without reading the database can not be unpleasant?)

    2. More secure, out of the database, preventing SQL injection, and so on.

    3. More conducive to the seo,html page is more easily included, this to webmaster friends, may be more concerned about.

Two, ASP. HTML Implementation method

Dry goods directly on the code:

Public static bool writefile (String strtext,string strcontent,string strauthor)     {    string path =  HttpContext.Current.Server.MapPath ("/news/");    encoding code =  Encoding.GetEncoding ("gb2312");    //  read template file    string temp =  httpcontext.current.server.mappath ("/news/text.html");    streamreader sr=null;     streamwriter sw=null;    string str= "";       try    {     sr = new  StreamReader (Temp, code);      str = sr. ReadToEnd (); //  Read file    }    catch (exception exp)      {     httpcontext.current.response.write (exp. Message); &nBsp;    httpcontext.current.response.end ();      sr. Close ();     }           string  htmlfilename=datetime.now.tostring ("YYYYMMDDHHMMSS") + ". html";    //  replace content     //  at this point, the template file has been read into the variable named str    str =str. Replace ("Showarticle", StrText),  //showarticle    str = str in the template page. Replace ("Biaoti", StrText);     str = str. Replace ("Content", strcontent);     str = str. Replace ("Author", Strauthor);    //  write file    try    {      sw = new streamwriter (path + htmlfilename ,  False, code);      sw. Write (str);      sw. Flush ();     }    caTCH (Exception ex)     {      HttpContext.Current.Response.Write (ex. Message);      httpcontext.current.response.end ();    }     FINALLY    {     SW. Close ();     }    return true;}
Source: http://www.csaspx.com/articlelist-6566.html

ASP. NET templates generate HTML 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.