The initial nvelocity template engine for ASP. NET Dynamic page static
Static page is the page code is in the page, do not need to execute asp,php,jsp,.net and other programs to generate the client page code page, static page URL is generally not included in the "?" "," = "," & "and other special symbols. Static pages can not manage the release of the updated page, if you want to update the content of the page, to the FTP software to the file down with the Web page making software modification (via FSO and other technical exceptions) common static page example:. html extension,. htm extension. Note: Static pages are not static pages that are not animated on the site.
Now we can simply implement the dynamic page static of the login process through the nvelocity template engine.
First we need to have an HTML static page
We can see that the value values in the page are the definitions that begin with $, which is to facilitate the next pass value.
Below we create a new C # generic handler to write code
Using system;using system.collections.generic;using system.linq;using system.web;using NVelocity.Runtime;using Nvelocity;using nvelocity.app;namespace czbk{///<summary>//Handler1 Summary description///</summary> Publ IC class Handler1:ihttphandler {public void ProcessRequest (HttpContext context) {CONTEXT.R Esponse. ContentType = "text/html"; String username = context. request["username"]; String Password = context. request["Password"]; if (string. IsNullOrEmpty (username) && string. IsNullOrEmpty (password)) {Velocityengine vltengine = new Velocityengine ();//Initialize Velocityengine engine Vltengine.setproperty (Runtimeconstants.resource_loader, "file");//The template file is located in the file system Vltengine.set Property (Runtimeconstants.file_resource_loader_path, System.Web.Hosting.HostingEnvironment.MapPath ("~/" );//the folder where the template file resides MapPath the server-side path is mapped to a physical path ' ~/' is located under the project root file Vltengine.init ();//instance Object initialization Velo Citycontext vltcontext = new Velocitycontext ();//Create a Context object//Vltcontext.put ("Data", data);//Set parameters, in the template can be Data to reference Vltcontext.put ("username", "" "); Vltcontext.put ("Password", "" "); Vltcontext.put ("msg", ""); Template vlttemplate = vltengine.gettemplate ("login.html"); System.IO.StringWriter vltwriter = new System.IO.StringWriter (); Vlttemplate.merge (Vltcontext, Vltwriter); String html = Vltwriter.getstringbuilder (). ToString (); Context. Response.Write (HTML); } else {if (username = = "Admin" && password = = "123") { Velocityengine vltengine = new Velocityengine ();//Initialize Velocityengine engine Vltengine.setproper Ty (runtimeconstants.resource_lOader, "file");//The template file is located in the file system Vltengine.setproperty (Runtimeconstants.file_resource_loader_path, System.Web.Hosting.HostingEnvironment.MapPath ("~/"));//the folder where the template file resides MapPath the server-side path is mapped to a physical path ' ~/' is located under the project root file Vltengine.init ();//instance object initialization Velocitycontext Vltcontext = new VELOCITYC Ontext ();//Create a Context object//Vltcontext.put ("Data", data);//Set parameters, which can be referenced by $data in the template Vltcont Ext. Put ("username", username); Vltcontext.put ("password", password); Vltcontext.put ("msg", "landing success"); Template vlttemplate = vltengine.gettemplate ("login.html"); System.IO.StringWriter vltwriter = new System.IO.StringWriter (); Vlttemplate.merge (Vltcontext, Vltwriter); String html = Vltwriter.getstringbuilder (). ToString (); Context. Response.Write (HTML); } else {velocityengine vltengine = new Velocityengine ();//Initialize Velocityengine engine Vltengine.setproperty (Runtimeconstants.resource_loader, "file");//The template file is located in the file system vltengine.se Tproperty (Runtimeconstants.file_resource_loader_path, System.Web.Hosting.HostingEnvironment.MapPath ("~/"));/ /template file Folder MapPath server-side path mapping to physical path//' ~/' located under Project root file Vltengine.init ();//Instance Object initialization Velocitycontext vltcontext = new Velocitycontext ();//Create a Context object//Vltcontext.put ("Data", DAT a);//Set parameters, in the template can be referenced by $data vltcontext.put ("username", username); Vltcontext.put ("password", password); Vltcontext.put ("msg", "Login Failed"); Template vlttemplate = vltengine.gettemplate ("login.html"); System.IO.StringWriter vltwriter = new System.IO.StringWriter (); VlttemplAte. Merge (Vltcontext, Vltwriter); String html = Vltwriter.getstringbuilder (). ToString (); Context. Response.Write (HTML); }}} public bool IsReusable {get {return false; } } }}
Such a simple landing function page static will be done
Ps
In general, some pages that do not update content frequently can consider static operations, such as the News page, the chapter page of the novel, after all, once the content has been published, it will rarely be changed. And you can use a CDN (the full name of the CDN is the Content Delivery network, which is the contents distribution networks. The basic idea is to avoid the bottleneck and link of the Internet which may affect the speed and stability of data transmission, and make the content transmission faster and more stable. By placing the node servers in the network, a layer of intelligent virtual network based on the existing Internet, the CDN system can re-direct the user's request to the nearest service node according to the network traffic and the connection of each node, the load condition and the distance and response time of the user. The goal is to enable users to get the content they need, solve the congestion of Internet networks, and improve the responsiveness of users to websites. ) technology to accelerate.
Advantages:
1, conducive to SEO, reflected in the friendly URL path and fast access speed, ASP. NET MVC site can ignore the impact of the URL.
2, a WORD: is fast!!! Static page access speed, good user experience, combined with CDN technology, caching and the corresponding architecture, speed up the effect more obvious!
3. Reduce server pressure to some extent compared to dynamic page
Disadvantages:
1, may need to use a lot of hard disk space
2, increase the complexity of website development, not conducive to the maintenance and management of the program.
3, not too flexible, static operation is required to trigger the switch, it is not possible to operate frequently, may result in slow data updates, the need for appropriate design.
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
The initial nvelocity template engine for ASP. NET Dynamic page static