20 practical examples of ASP programming (1)

Source: Internet
Author: User

1. How to use Asp to determine the virtual physical path of your website

A: Use 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 can I know the browser used by the user?

A: 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: Solution

<% Startdate = DateDiff ("d", Now, "01/01/1990 ")
If strdate <0 then startdate = startdate *-1
Avgvpd = Int (usercnt)/startdate) %>

Display result

<% Response. write (avgvpd) %>
That 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"
%>


Display

5. How to return to the previous page

A: <a href = "<% = request. serverVariables (" Http_REFERER ") %>"> preivous page </a>


Or use an image, such:

6. How to Determine the IP address of the other party

Answer: <% = Request. serverVariables ("REMOTE_ADDR) %>

7. How to link to an image

A:

<% @ Ages = vbs packages %>
<% Response. expires = 0
Strimagename = "graphix/errors/erroriamge.gif"
Response. redirect (strimagename)
%>

8. Force password input dialog box

A: Put this sentence at the beginning of the page.

& Lt; % response. status = "401 not Authorized"
Response. end
%>


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.