Use Server.Transfer to hide the URL and others

zhaozj2021-02-16  47

Use Server.Transfer to hide the URL and others

August 29, 2003

1 question

Often see some websites or web applications, in the browser, they only use a page, all page addresses are obtained through the parameter link of this page. E.g:

Http://abc.com/default.asp?pg=adminPage&command=view

http://abc.com/default.asp?pg=showpage&command=List

Waiting for this thing. I didn't think about it carefully. Maybe the page is different from a few different SUBs; but I look at the two addresses. The difference between the two pages is too big; if this page contains this Many Sub, this is a destruction of programmers, and the beauty is not able to intervene. I was discussed with a netizen for a long time. He raised it with isapi, I felt horrible.

Later, I thought about it, remembered several ways to turn to: Server.Transfer, response.Redirect, server.execute is not enough. Response.Redirect is IIS clearly indicating that it is not used (but I used to use the most when I did ASP). Later, look at the server.transfer, the more you think, you can use it. The help of IIS is described below:

When you call Server.Transfer, the state information for all the built-in objects will be included in the transfer. This means that any variables or objects that have been assigned a value in session or application scope will be maintained. In addition, all That is, all Request collections, session, application are shared. This can interact in different pages.

Seeing these, I did some code to do it, explain the following:

2 implementation

My initial idea is: Record all names-address control collections in an XML file, then read this collection in Default.asp, read Page Name in the PG of the query string, then Server.Transfer to the corresponding On the page. The key code is as follows:

DEFAULT.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 did not pass a pg parameter." Response.End End If If OpageURL = "" Then Response.write "Can't find the mapping file for:" & opageName Else Server.Transfer (OpageURL) end ifif 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") 'The page address acquired pageName Function GetPage (pageName) If Page_URL_Dict.Count = 0 THENERLTODIC END IF

GetPage = Page_URL_DICT (PAGENAME) END FUNCTION

'Initialization PageName-PageURL Control Dictionary Function READPAGEURLTODICT () ON Error ResMe 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 & "
" response.write err.description & "
" end if end function%>

App-conf.xml

pghome Page2.asp pgshownews shownews-1_0.asp PGHTML 1.html 3 practice and problem

Enter http: // localhost: 12345 / default.asp? Pg = pghome in the browser

Http: // localhost: 12345 / default.asp? pg = pgshownews See the same name between the different pages, no feeling of obvious steering. I made a page of Request.Form, request.QueryString, and I can get the corresponding value.

problem:

If the page to be turned, if you are in other directories, and if you have a reference to ../ superior directory or other directory in this page, you can't display it. I think this may be that the server.transfer is actually executing the entire file to the current path. This will have a problem with this image, style, etc. That is, if you want to apply this method throughout the system, you need to place all page files (ASP, HTML) in the same folder with Default.asp (or other control steering). This is more or less.

4 advantages:

The most direct advantage of this way is to separate the links to the file name. You don't need to spend a speech, you don't need to take a file name, nor does it need to take the right to check the correctness of the link address. Just map Pagename with PageURL in the XML file.

The second advantage is safe, and users cannot know your true URL address. You can also add some controls in Default.asp, making users directly accessing xxx.asp to an error page.

The third advantage is easy to manage. By mapping the file name - file path, you can more clear the process of the entire project. If you like, you can standardize the parameters belled in the page. In this way, the ASP project can also standardize, for example, a typical page address:

http://abc.com/default.asp?pg=pgnewslist&command=List&sp=1&sp=abc

By standardizing the page name, parameters, the programmer can be more clearly written. Project managers can quickly grasp the context of the entire item by mastering the entire XML profile (of course, parameter information, page description, etc.). This also controls the problem of adding files to a certain extent. Of course, the above is just some of my thoughts, after all, don't do ASP now, many ideas don't know if I can really realize. I also hope that everyone will come together. Email: mechiland@163.net

转载请注明原文地址:https://www.9cbs.com/read-27992.html

New Post(0)