Dynamic include method in ASP

Source: Internet
Author: User
Recommendation
============================
ASP dynamic include file
Example: Include ("youinc. asp ")
<%
Function include (filename)
Dim re, content, FSO, F, aspstart, aspend
Set FSO = Createobject ("scripting. FileSystemObject ")
Set F = FSO. opentextfile (server. mappath (filename ))
Content = f. readall
F. Close
Set F = nothing
Set FSO = nothing
Set Re = new Regexp
Re. pattern = "^ \ s * ="
Aspend = 1
Aspstart = instr (aspend, content, "<%") + 2
Do While aspstart> aspend + 1
Response. Write mid (content, aspend, aspStart-aspEnd-2)
Aspend = instr (aspstart, content, "% \>") + 2
Execute (Re. Replace (mid (content, aspstart, aspEnd-aspStart-2), "response. Write "))
Aspstart = instr (aspend, content, "<%") + 2
Loop
Response. Write mid (content, aspend)
Set Re = nothing
End Function
%>
============================

<% If xxx = "yyy" then %>
<! -- # Include file = "file1.asp" -->
<% Else %>
<! -- # Include file = "file2.asp" -->
<% End if %>
This will download unnecessary documents and affect the loading efficiency.

1)
If xxx = "yyy" then
Server. Execute ("file1.asp ")
Else
Server. Execute ("file2.asp ")
End if

2)
If xxx = "yyy" then
Server. Transfer ("file1.asp ")
Else
Server. Transfer ("file2.asp ")
End if

3)
If xxx = "yyy" then
Filespec = "file2.asp"
Else
Filespec = "file2.asp"
End if
Filespec = server. mappath (filespec)
Scr = "scripting. FileSystemObject"
Set FS = server. Createobject (SCR)
Set F = FS. opentextfile (filespec)
Content = f. readall
Set F = nothing
Set FS = nothing
Response. Write (content)

Note the following when using the above methods to implement the include function. We can set <! -- # Include file = "file. ASP "--> contains the webpage file. ASP is considered to contain file. an integral part of an ASP Web page is to save the content of the web page as another file. It can be said that they are originally a Web page, so the contained web page file. ASP inherits files. all parameter settings of ASP Web pages, including sessions, are not the same as those of other methods. The HTML syntax can be shared with the main web page, while ASP is independent, in general, special sessions cannot be transferred from the primary webpage to the contained webpage file. ASP.

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.