Some of the previously collected data---Using ASP's error traps to implement Web site virtual directory functions

Source: Internet
Author: User
Tags error handling iis implement trim
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>



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.