Error | Virtual directory uses ASP's error trap to implement Web site virtual directory function
I think you've all seen it. This virtual directory feature is available on many sites that provide a personal homepage.
Is that Http://xxx.xxx.xxx/~Batman will be connected to my homepage (assuming I have this homepage, hehe)
So how do we use pure ASP technology to implement this functionality, such as on chinaasp if
Is the connection Http://www.chinaasp.com/~Batman automatically connected to the personal information associated with Batman?
An error trap technique using ASP is described below:
We all know that there is a custom error handling feature in IIS that I've introduced several times before.
Select the default Web site from IIS Control Manager and right-click, select Properties, and then select a custom
Error, and then click Edit ... buttons, etc...
All right. Now redefine the HTTP 404 error to use asperr.asp this file
Of course, the code for this file is down there.
The file asperr.asp code is as follows:
<%
Strtarget = Request.ServerVariables ("query_string")
' * * * See whether the call to the virtual directory format is the beginning of the "~" character
If InStr (Strtarget, "~") Then
' * * * character processing, remove the "~" and "in the string." ASP "
Stralias = Trim (Right (Strtarget, Len (strtarget)-InStr (Strtarget, "~"))
Stralias = LCase (replace (UCase (Stralias), ". ASP "," "))
If Trim (stralias) <> "" Then
' * * * Query exists this username (that is, virtual directory)
Set rectemp = Server.CreateObject ("ADODB. RecordSet ")
Rectemp.source = "Select user_id, List_type from users where Alias_file = '" & Replace (Stralias, "'", "'") & "")
Rectemp.activeconnection = Condb
Rectemp.open
' * * * Inquiry personal information, and display his information, I temporarily borrow bird brother wrote
' Myinfo.asp file, don't knock me Oh, hehe
If not (RECTEMP.BOF and rectemp.eof) then
Strredir = "myinfo.asp?user_id=" & Server.URLEncode (Trim (rectemp ("user_id"))
Rectemp.close
Set rectemp = Nothing
Response.Redirect Strredir
End If
Rectemp.close
Set rectemp = Nothing
End If
End If
' * * * * If you can not find the application of the user name of the virtual directory, it will show errors
Response.Status = "404 Not Found"
%>
<body>
404 Not Found
</body>