Static Page implementation in ASP

Source: Internet
Author: User
Tags servervariables

1. Use isapi_rewrite for Dynamic Link rewriting of HTML static URL. Isapi_rewrite is a DLL component, and re_write is a module in IIS. This filter maps Dynamic Web URLs to static Web URLs through regular expressions. If news. asp? Id = 95 convert it to news/95.html through re_write. The ing regular expression is set in the httpd. ini file.
For example, to process data paging, the statement is as follows:
More _ <% = Page % >_< % = type %>. html (Note: page is the page turning page and type is the data type) Format: more_rj95.html
If the next page is turned over, it is: more_2_95.html. To continue the next page loop, it is:
More_3_95.html, and so on.
However, you need to add the following to the httpd. ini file: Code :
Rewriterule/more_(d1_0000_(d1_0000.html/jsp tutorial/more. asp? Page = $1 & type = $2 [N, I] string 9
If your dynamic Program If multiple parameters need to be passed, add multiple (D +) as follows:
Rewriterule/more_(d1_0000_(d1_0000_(d1_0000.html/asp/more. asp? Page = $1 & type = $2 & type2 = $3 [N, I]
Advantage: No changes are required in the program. Trouble: To achieve this, you need to control IIS. Therefore, when you rent someone else's server, you need to contact the service provider first. (Of course, this is for ASP, the Asp.net tutorial does not need to -- directly put the DLL assembly into the bin of the program and then implement the appropriate configuration)
2. IIS 404 error handling mechanism: Turn to the prepared processing page through custom errors. However, this scalability remains to be studied, and the overall requirements for program processing are also high, which is not suitable for practical applications.
First, set site properties-custom errors
Locate HTTP Error 404, edit properties, select the URL for the message type, and enter "/index. asp" in the URL, or enter your error handling page.
In this way, when a user or a spider accesses http: // cN/12345.html (12345 is Article In the database tutorial ID). Because some pages do not exist, the 404 error is triggered and the index. asp
Add in index. asp

Copy code The Code is as follows: currdomain = request. servervariables ("http_host") 'current access domain name
Currurl = Replace (request. servervariables ("QUERY_STRING"), "404; http: //" & currdomain & ": 80", "") 'current access URL

The currurl should be 12345.html.
3.
1. Create a folder Info (because the page URL of the final access information is http: // localhost/INFO /? 1. html)
2. Create a default. asp file in the info folder (that is, the page of the default homepage)
The content of the default. asp file is as follows:Copy codeThe Code is as follows: <%
Currdomain = request. servervariables ("http_host") 'current access domain name
Currurl = Replace (request. servervariables ("QUERY_STRING"), "404; http: //" & currdomain & "/INFO /? "," ") 'Current access URL
Id = Replace (currurl, ". html ","")
%>

ID is the input parameter.
If there are multiple parameters, you can convert the URL pseudo-static to info /? 1-2-3.html
The values 1, 2, and 3 represent the values of the three parameters, which can be separated by strings.
Real HTML static page
Write the HTML code to the file and generate a. html file. Copy code The Code is as follows: <%
Filename = "test.htm"
If request ("body") <> "then
Set FSO = server. Createobject ("scripting. FileSystemObject ")
Set htmlwrite = FSO. createtextfile (server. mappath ("" FILENAME ""))
Htmlwrite. Write "<HTML> Htmlwrite. write "<body> output title content:" request. form ("title") "<br/> output body content:" request. form ("body") "</body> Htmlwrite. Close
Set fout = nothing
Set FSO = nothing
End if
%>
<Form name = "form" method = "Post" Action = "">
<Input name = "title" value = "title" size = 26>
<Br>
<Textarea name = "body"> body </textarea>
<Br>
<Br>
<Input type = "Submit" name = "Submit" value = "generate html">
</Form>

2. However, it is inconvenient to generate HTML files according to the above method. The second method is to use the template technology, replace the value of special code in the template with the value accepted from the form or database field to complete the template function. generate an HTML file for all the final replaced template code. this technology is widely used, and most CMS uses this method.
Template.htm' // Template File Copy code The Code is as follows: <HTML>
<Head>
<Title> $ title $ by aspid.cn </title>
</Head>
<Body>
$ Body $
</Body>
</Html> testtemplate. asp '// generate html
<%
Dim FSO, htmlwrite
Dim strtitle, strcontent, Strout
'// Create a file system object
Set FSO = server. Createobject ("scripting. FileSystemObject ")
'// Open the webpage template file and read the template content
Set htmlwrite = FSO. opentextfile (server. mappath ("template.htm "))
Strout = f. readall
Htmlwrite. Close
Strtitle = "generated webpage title"
Strcontent = "generated webpage content"
'// Replace the tag in the template with the actual content
Strout = Replace (Strout, "$ title $", strtitle)
Strout = Replace (Strout, "$ body $", strcontent)
'// Create the static page to be generated
Set htmlwrite = FSO. createtextfile (server. mappath ("test.htm"), true)
'// Write the webpage content
Htmlwrite. writeline Strout
Htmlwrite. Close
Response. Write "static page generated successfully! "
'// Release the File System Object
Set htmlwrite = nothing
Set FSO = nothing
%>

Related Article

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.