The initial nvelocity template engine for ASP. NET Dynamic page static

Source: Internet
Author: User
Tags hosting node server

The initial nvelocity template engine for ASP. NET Dynamic page static

Static page is the code of the page is in the page, do not need to run 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 be managed to publish updated pages, false assumptions to update the content of the page, to the FTP software to the file down with the Web page making software changes (through the 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 find 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 directory where the template file is located the Mappathserver-side path is mapped to a physical path                                                ' ~/' is located under the project root file Vltengine.init ();//instance Object initialization Ve Locitycontext vltcontext = new Velocitycontext ();//Create a Context object//Vltcontext.put ("Data", data);//Set the number of parameters.                In the template can be referred to Vltcontext.put ("username", "" ") through $data;                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 ("~/"));//directory where the template file is located the Mappathserver-side path maps to a physical path ' ~/' is located under the project root file Vltengine.init ();//instance object initialization Velocitycontext Vltcontext = new Veloc Itycontext ();//Create a Context object//Vltcontext.put ("Data", "data");//Set the parameters to refer to the VLT by $data in the template                    Context.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 Vltengin E.setproperty (Runtimeconstants.file_resource_loader_path, System.Web.Hosting.HostingEnvironment.Map Path ("~/"));//The directory where the template file is located mappathserver the path map to the physical path//' ~/' under the project root file Vltengine.init ();//Real Example Object initialization Velocitycontext Vltcontext = new Velocitycontext ();//Create a Context object//Vltcontext. Put ("Data", data);//Set the number of 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 frequently update content can be considered for static operations. For example, the News page, the chapter page of the novel, after all, these content once published, it is very rarely modified. And be able to use CDN (the full name of the CDN is the content Delivery network, i.e. The basic idea is to avoid the bottleneck and link of the Internet which may affect the speed and stability of transmission data, and make the content transmission faster and more stable. By placing node server in the network, a layer of intelligent virtual network which is based on the existing Internet, the CDN system can direct the user's request to the user's nearest service node in real-time 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 to address the congestion of Internet networks. Increase the responsiveness of users to the site. ) technology to accelerate.

Strengths:

1, conducive to SEO, the body is now a friendly URL path and high-speed access to the speed, ASP. NET MVC site can ignore the impact of the URL.

2, a WORD: is fast!!! The static page access speed is fast. User experience is good. Combined with CDN technology, cache and corresponding architecture, the speed-up effect is 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. Add the complexity of site development. Not conducive to program maintenance and management.

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 corresponding design.

The initial nvelocity template engine for ASP. NET Dynamic page static

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.