Very simple, but I finally got it ~
Use the stringtemplate template engine ~ The original template was written in. cs. After separation, it seems that the speed is much slower... It is estimated that it will be cached ~ I don't know if there are any better suggestions.
Template page <! Doctype HTML public "-// W3C // dtd xhtml 1.0 transitional // en" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" >
< Html Xmlns = "Http://www.w3.org/1999/xhtml" >
< Head >
< Title > $ Title $ </ Title >
</ Head >
< Body >
$ Var $
</ Body >
</ Html >
. ASPX page <% @ Page Language = " C # " Autoeventwireup = " True " Codebehind = " Default. aspx. CS " Inherits = " Templatetest. _ default " %>
. CS page Using System;
Using System. Web;
Using Anlr. stringtemplate;
Using System. IO;
// Using anlr. stringtemplate. language;
// Using anlr. collections;
Namespace Templatetest
{
Public Partial Class _ Default: system. Web. UI. Page
{
Protected Void Page_load ( Object Sender, eventargs E)
{
Stringtemplate St = New Stringtemplate (read ( " Default.htm " ));
St. setattribute ( " Title " , " Example 1 " );
St. setattribute ( " VaR " , " Hello World " );
Response. Write (St. tostring ());
}
Public Static StringRead (StringFilename)
{
Filename = Httpcontext. Current. server. mappath ( " ~ /Template/ " + Filename );
Using (Filestream FS = New Filestream (filename, filemode. Open, fileaccess. Read ))
{
Streamreader SR = New Streamreader (FS );
Return Sr. readtoend ();
}
}
}
}
and