ASP Programming-20 Common examples

Source: Internet
Author: User
Tags command line servervariables root directory
Programming 1. How to use ASP to judge the virtual physical path of your website

Answer: Using the MapPath method
<palign= "Center" ><fontsize= "4" face= "Arial" ><b>
Thephysicalpathtothisvirtualwebsiteis:
</b></font>
<fontcolor= "#FF0000" size= "6" face= "Arial" >
<%=server.mappath ("\")%>
</font></p>



Answer: Using the Therequestobject method
Strbrowser=request.servervariables ("Http_user_agent")
Ifinstr (Strbrowser, "MSIE") <>0then
Response.Redirect ("formsieonly.htm")
Else
Response.Redirect ("forall.htm")
EndIf



Answer: the solution
<%startdate=datediff ("D", Now, "01/01/1990")
Ifstrdate<0thenstartdate=startdate*-1
Avgvpd=int ((usercnt)/startdate)%>
Show results
<%response.write (AVGVPD)%>
thatisit.thispagehavebeenviewedsincenovember10,1998



<%dimp,ppic,dpic
Ppic=12
Randomize
P=int ((ppic*rnd) +1)
Dpic= "graphix/randompics/" &p& ". gif"
%>
Show




Answer: <ahref= "<%=request.servervariables" ("Http_referer")%> ">preivouspage</a>
Or with pictures such as:



Answer: <%=request.servervariables ("REMOTE_ADDR")%>



Answer: <% @Languages =vbscript%>
<%response.expires=0
Strimagename= "Graphix/errors/erroriamge.gif"
Response.Redirect (Strimagename)
%>



A: Put this sentence on the beginning of the page
<%response.status= "401notAuthorized"
Response.End
%>



A: Use the hidden type to pass variables
<%formmethod= "POST" action= "mynextpage.asp" >
<%foreachiteminrequest.form%>
<inputnamee= "<%=item%>" type= "HIDDEN"
Value= "<%=server. HTMLEncode (Request.Form (item))%> ">
<%next%>
</form>



Answer: Because the ASP is the server running, if you can display a dialog box on the server, then you have to wait for someone to make sure that your program can continue to execute, and the general server will not be guarded, so Microsoft has to prohibit this function, and told you (:) hehe) do not have permission. However, ASP and client-side scripting can be combined to display a dialog box, Asfollows:
<%yourvar= "Test dialog box"%>
<%scriptlanguage= ' JavaScript ' >
Alert ("<%=yourvar%>")
</script>



A: You can download a Microsoft Windowsscriptencoder, it can encrypt the ASP script and client Javascript/vbscript script ... However, after the client encryption, only IE5 can execute, server-side script encryption, only the server installed Scriptengine5 (install a IE5) to perform.



A: The former file adds the following sentence: Response.Redirect ("second.asp?") &request.servervariables ("Query_string"))



A: Only the web directory is set to Webapplication,global.asa, and the Global.asa of a webapplication root directory is valid. IIS4 can use Internetservicemanager settings applicationsetting How can I make an HTM file Execute script code just like an ASP file?



Answer:internetsevicesmanager-> Select defaultwebsite-> right mouse button-> Menu Properties-〉 Home directory-> application settings (applicationsetting)-> Click button "Configure "->appmapping-> Click on the button" Add "->executablebrowse select \winnt\system32\inetsrv\asp. Dllextension input Htmmethodexclusions input put.delete all OK. However, it should be noted that the HTM is also handled by Asp.dll, and the efficiency will be reduced.



Answer: There are two ways.
The first method: Manually registering DLLs This method has been used from IIs3.0 to IIs4.0 and other webserver. It requires you to run down the command line, into the directory containing the DLL, and enter: Regsvr32component_name.dll for example C:\temp\ Regsvr32AspEmail.dll It registers specific information about the DLL into the registry on the server. This component can then be used on the server, but there is a flaw in this approach. When the component is registered with this method, the component must be set to the appropriate NT anonymous account to execute the DLL. In particular, some components need to read the registry, so the method of registering the component is simply using the server without MTS, to unregister the DLL, using: regsvr32/uaspobject.dllexamplec:\temp\regsvr32/ Uaneiodbc.dll

The second approach: using MTS (MICROSOFTTRANSACTIONSERVER) MTS is a new feature of IIS4, but it provides a huge improvement. MTS allows you to specify that only privileged users have access to the component, greatly improving the security settings on the Web server. The steps for registering a component on MTS are as follows:
1 Open the IIS Management Console.
2) Expand Transactionserver, right-click "Pkgsinstalled" and select "Newpackage".
3) Click "Createanemptypackage".
4) name the package.
5 Specify the Administrator account or use "interactive" (if the server is often logged in with the administrator).
6 now use the right mouse button to click the "Components" that you started underneath the package you just created. Select "Newthencomponent".
7 Select "Installnewcomponent".
8 Locate your. dll file and select next to complete.
To delete this object, simply select its icon, and then select Delete.
Note: In particular, note the second method, which is the best way to debug your own writing components, without having to reboot the machine every time.



<% @language =vbscript%>
<%
Dimconn,mdbfile
Mdbfile=server.mappath ("database name. mdb")
Setconn=server.createobject ("Adodb.connection")
Conn.Open "Driver={microsoftaccessdriver (*.mdb)};uid=admin;pwd= database password; dbq=" &mdbfile

%>



<% @language =vbscript%>
<%
Dimconn
Setconn=server.createobject ("Adodb.connection")
Con.open "Provider=sqloledb;datasource=sql server name or IP address; Uid=sa; pwd= database password; database= database name
%>

To set up a Recordset object:

Setrs=server.createobject ("Adodb.recordset")
Rs.opensql statement, conn,3,2

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.