15 very useful examples in ASP programming

Source: Internet
Author: User
Tags iis variables servervariables valid client root directory
Programming how to use ASP to determine the virtual physical path of your Web site

Answer using the MapPath method

<p align= "center" ><font size= "4" face= "Arial" ><b>
The physical path to this virtual website is:
</b></font>
<font color= "#FF0000" size= "6" face= "Arial" >
<%= Server.MapPath ("\")%>
</font></p>

2. How do I know the browser used by the user?

To use the Request object method

Strbrowser=request.servervariables ("Http_user_agent")
If Instr (Strbrowser, "MSIE") <> 0 Then
Response.Redirect ("formsieonly.htm")
Else
Response.Redirect ("forall.htm")
End If

3. How to calculate the average number of repeated visits per day

Answer the solution

<% Startdate=datediff ("D", Now, "01/01/1990")

If Strdate<0 then startdate=startdate*-1

Avgvpd=int ((usercnt)/startdate)%>

Show results

<% Response.Write (AVGVPD)%>

This is It.this page have been viewed since November 10,1998

4 How to display random images

〈% Dim P,ppic,dpic

Ppic=12

Randomize

P=int ((ppic*rnd) +1)

Dpic= "graphix/randompics/" &p& ". gif"

%>

Show

〈img src= "<%=dpic%>>" >

5. How to get back to the previous page

Answer <a href= "<%=request.servervariables (" Http_referer ")%>" >preivous page</a>

Or with pictures such as: ">

6. How to determine the IP address of each other

Answer 〈%=request.servervariables ("REMOTE_ADDR")%>

7. How to link to a picture

<% @Languages =vbscript%>

<% response.expires=0

Strimagename= "Graphix/errors/erroriamge.gif"

Response.Redirect (Strimagename)

%>

8. Forced Enter Password dialog box

This is the beginning of the page.

<% response.status= "401 Not Authorized"

Response.End

%>

9 How to pass variables from one page to another

You should use the hidden type to pass variables

<% form method= "POST" action= "mynextpage.asp" >

<% for each item in Request.Form%>

<input namee= "<%=item%>" type= "HIDDEN"

Value= "<%=server. HTMLEncode (Request.Form (item))%> ">

<% Next%>

</form>

10 Why I use MsgBox in the ASP program, the program error said no permissions

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 confirm, your program can continue to execute, and the general server will not be guarded, so Microsoft had to ban this function, and told you at random (:) OH) No permissions. However, ASP and client-side scripting can be combined to display a dialog box, as follows:

<% yourvar= "Test dialog box"%>

<% script language= ' JavaScript ' >

Alert ("<%=yourvar%>")

</script>

11 There is no way to protect their source code, do not give people to see

You can download a Microsoft Windows Script Encoder, which can encrypt the ASP script and the client Javascript/vbscript script ... However, after the client is encrypted, only IE5 can execute, server-side script encryption, only the server installed script engine 5 (installed a IE5 have) to perform.

12 How can I transfer query string from one ASP file to another?

The first document to add the following sentence: Response.Redirect ("Second.asp?" & Request.ServerVariables ("Query_string"))

Global.asa files always don't work?

Global.asa is valid only if the Web directory is set to Web application, and Global.asa is valid under the root directory of a Web application. IIS4 can use Internet Service Manager to set application setting how can I make an HTM file Execute script code just like an ASP file?

14 How can I make an HTM file Execute script code like an ASP file?

Answer Internet sevices Manager-> Select Default Web site-> right mouse button-> Menu Properties-〉 Home directory-> application settings (Application Setting)-> Click button "Configure" -> app mapping-> Click on the button "Add"-> executable browse select \winnt\system32\inetsrv\asp. DLL EXTENSION input HTM method exclusions input put.delete all OK but it is worth noting that the HTM is also handled by Asp.dll, and the efficiency will be reduced

15 How to register components

There are two ways of answering

The first method: Manually registering DLLs This method is used from IIS 3.0 to IIS 4.0 and other Web servers. It requires you to execute it on the command-line, enter the directory containing the DLL, and enter:: \\regsvr32 component_name.dll For example, C:\temp\regsvr32 AspEmail.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/u Aspobject.dll Example c:\temp\regsvr32/u Aneiodbc.dll

The second approach: using MTS (Microsoft Transaction Server) MTS is a new feature of IIS 4, but it provides a great deal of 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: I opens the IIS management Console. II Expand Transaction Server, right-click "pkgs Installed" and select "New Package" III) Click "Create an empty package" IV to name the packet V) specify Administrat or Account or use "interactive" (if the server is often logged in with the administrator) now use the right mouse button to click the "Components" after the package that you just created. Choose



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.