Server 1 problem raised
Often see a number of Web sites or Web applications, in the browser, they only use a page, all the page addresses are through the parameters of the page link. For example:
Http://abc.com/default.asp?pg=AdminPage&command=View
Http://abc.com/default.asp?pg=ShowPage&command=List
and all that stuff. I didn't think about how to make it happen before. Perhaps the page difference is not a few different sub to do on the line, but look at the two addresses, two pages of the difference is too large, if this page contains so many sub, this is a very devastating for programmers, and art can not interfere. I talked with a net friend for a long time, he proposed to use ISAPI, I feel very terrible.
Later thought, remember to turn several methods: Server.Transfer, Response.Redirect, Server.Execute not forget. Response.Redirect is clearly not used by IIS (but I used the most when I used to do ASP). Later look at the Server.Transfer, the more you can see the use of the appearance. The following is explained in the help of IIS:
When your call is Server.Transfer, the state information to all the built-in objects'll be included in the Transfer. This means so any variables or objects is have been assigned a value in session or application scope would be maintaine D. In addition, all of the current contents for the request collections is available to the. asp file receiving the T Ransfer. In other words, all request collections, sessions, and application are shared. This allows you to interact with different pages.
Seeing this, I started to do some code, elaborated as follows:
2 implementation
My initial idea was to record all the name-address control sets in an XML file, read the collection in Default.asp, read page name in PG of the query string, and then server.transfer to the corresponding page. The key code is as follows:
Default.asp:
<!--#include file= "functions.asp"-->
<%
On Error Resume Next
Response.Charset = "gb2312"
Dim Opagename, Opageurl
Opagename = Request.QueryString ("PG")
If opagename <> "" Then
Opageurl = GetPage (opagename)
Else
Response.Write "Okok, you didn ' t pass a PG parameter."
Response.End
End If
If Opageurl = "" Then
Response.Write "Mapping File not found for:" & Opagename
Else
Server.Transfer (Opageurl)
End If
If err.number <> 0 Then
Response.Write Err.Description
End If
%>
Functions.asp:
<%
Option Explicit
Dim Configpath, Page_url_dict
Configpath = Server.MapPath ("./conf/app-conf.xml")
Set page_url_dict = Server.CreateObject ("Scripting.Dictionary")
' Get the page address according to PAGENAME
Function getpage (PAGENAME)
If page_url_dict.count = 0 Then
Readpageurltodict
End If
GetPage = page_url_dict (pagename)
End Function
' Initialize Pagename-pageurl control dictionary
Function readpageurltodict ()
On Error Resume Next
Page_url_dict.removeall
Dim Lognode, XMLDOM, Root
Set xmldom = Server.CreateObject ("Microsoft.XMLDOM")
Xmldom.async = False
Xmldom.load (Configpath)
Set root = Xmldom.selectsinglenode ("//url-mappings")
For each lognode in Root.childnodes
Page_url_dict.add lognode.childnodes (0). Text, Lognode.childnodes (1). Text
Next
Set xmldom = Nothing
If err.number <> 0 Then
Response.Write Err.Source & "<br>"
Response.Write Err.Description & "<br>"
End If
End Function
%>
App-conf.xml
<?xml version= "1.0"?>
<app-conf>
<url-mappings>
<url-mapping>
<page-name>pgHome</page-name>
<page-url>Page2.asp</page-url>
</url-mapping>
<url-mapping>
<page-name>pgShowNews</page-name>
<page-url>shownews-1_0.asp</page-url>
</url-mapping>
<url-mapping>
<page-name>pghtml</pag