asp常用的一些基本知识

原创 2005年05月13日 19:37:00

''''''''''''''''''''''''''''''''''''''

''''''''''''''''''''''''''''''''''''''
'转向其他的页面。。。。。。。

<html>
<head>
<meta http-equiv="refresh" content="3;url=index.asp">
<script language="javascript">
<!--
function redirect(){top.window.location.href="index.asp"}
//-->
</script>
</head>
<body onload="redirect()">
<a href="index.asp" target="_top">Click here to continue!</a>
</body>
</html>
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'Browser Capabilities组件,判断浏览器类型等
'浏览器的信息保存在browscap.ini的文本中,在system32/inetsrv/下
<%@language="vbscript"%>
<%
nlnIsIE4=false
set objBCap=Server.CreateObject("MSWC.BrowserType")
if objBCap.browser="IE" and objbCap.version>=4 then blnIsIE4=true
if objBCap.ActivexControls then ...
%>
<%if blnIsIE4 then%>
.....
<%end if%>


''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'可以判断浏览器类型
<%@language=vbscript%>
<%strUA=request.ServerVariables("HTTP_USER_AGENT")%>
<%
QUOT=Chr(34)
if InStr(strUA,"MSIE") then "it is a microsoft browser"
intVersion=CInt(Mid(strUA,InStr(strUA,"MSIE")+5,1))
%>

''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

<input type=SUBMET VALUE="lark" ONCLICK="windows.status='searching...';document.MyForm.submit();">

<script language="javascript">
<!--
var sorryText='sorry,cannot display the color depth of your system';
if(navigator.appName.indexof('netscape')!=-1)
 if(navigator.appVersion.substr(0,1)>3)
  document.write('system color depth is '+windows.screen.pixelDepth)
 else
  document.write('sorryText');

if(navigator.appName.indexOf('Microsoft')!=-1)
 if(navigator.appVersion.substr(0,1)>3)
  document.write('system color depth is '+windows.screen.colorDepth)
 else
  document.write(sorrytext);

//-->
</script>

''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'window.location.href='index.asp' 等效于
'response.clear
'response.redirect "index.asp"


''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'读Cookies!
<B>the contents of your Cookies are:</B>
<%
for each item in request.cookies
  if request.cookies(item).HashKeys then
     for each itemkey in request.cookies(item)
         response.write item & "(" & itemkey & ")="_
         & request.cookies(item)(itemkey) & "<BR>"
     next
  else response.write item & "=" & request.cookies(item) & "<BR>"
 end if
next
%>

''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''


''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'设置超时值
<%@language="vbscript"%>
<!--#include virtual="/common/connect.inc"//-->
<%
Server.ScriptTimeOut=2400       'will probably take a while to run
seekTitletimeOut=45             'seconds to wait for page to arrive
%>

'设置Cookies的过期时间
<script language="javascript">
<!--
function getOpinions()
{
  strCookie=document.cookie;
  if(strCookie.indexof("doneOpinions=True")<0)
  {
    theDate=new Date();
    theDay=theDate.getDate()+14;         //gets the day of the month
    if(theDay>28)
    {
     theDay=theDay-28;
     theMonth=theDate.getMonth()+1;
     theDate.setMonth(theMonth);
    };
    theDate.setDate(theDay);              //sets the day of the month
    strDate=theDate.toGMTString();        //expiry dates must be UNC(GMT)
    document.cookie="DoneOpinions=true;path=/;expires="+strDate;
    window.open("/common/opinion.htm","opinion_win",
                "resizable=yes,scrollbars=no,status=no,"
                +"location=no,directories=no,status=no,"
                +"menubar=no,width=360,height=200,top=5,left=5")
  }
}
//-->
</script>


''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'收集会话者信息
create teble dbo.sessions
{
  EventDateTime datatime not null default GETDATE(),
  EventType varchar(50) null,
  URL varchar(255) null,
  Referer varchar(255) null,
  RemoteHost varchar(255) null,
  UserAgent varchar(255) null,
  UALanguage varchar(255) null,
  SessionCount int null,
  UserID int null,
  HostIP varchar(255) null
}
'下列代码在global.asa文件中
<script language="vbscript runat=server">
sub Application_onStart()
  on Error Resume next
  strSQL="insert into Sessions(EventType) VALUES('Application Start')"
  writeSessionData strSQL
end sub

sub session_onStart()
  on Error Resume next
  strSQL="insert into Sessions"_
         &"(EventType,URL,Referer,RemoteHost,UserAgent,"_
         &"UALanguage,UserID,HostIP)"_
         &" Values('New Session','"_
         &request.ServerVariables("URL")&"','"_
         &request.ServerVariables("HTTP_REFERER")&"','"_
         &request.ServerVariables("REMOTE_HOST")&"','"_
         &request.ServerVariables("HTTP_USER_AGENT")&"','"_
         &request.ServerVariables("HTTP_ACCEPT_LANGUAGE")&"','"_
         &CLng(Session.SessionID)&",'"_
         &request.ServerVariables("LOCAL_ADDR")&"')"
  writeSessionData strSQL
end sub

sub Application_onEnd()
  On Error Resume next
  strSQL="insert into sessions(EventType) VALUES('Application end')"
  WriteSessionData strSQL
end sub


sub Session_onStart()
  on Error Resume next
  strEntry=FormatDataTime(Now())&","
           &request.ServerVariables("URL")&","_
           &request.ServerVariables("HTTP_REFERER")&","_
           &request.ServerVariables("REMOTE_HOST")&","_
           &request.ServerVariables("HTTP_USER_AGENT")&","_
           &request.ServerVariables("HTTP_ACCEPT_LANGUAGE")&","_
           &CLng(Session.SessionID)&","_
           &request.ServerVariables("LOCAL_ADDR")&")"
  WriteSessionString strEntry          'a custom routine to write the string to a file
end sub

sub Session_onEnd()
  On Error Resume next
  strSQL="insert into Sessions(EventType,UserID)"_
         &"Values('Session end',"&CLng(Session.SessionID)&")"
  WriteSessionData strSQL
end sub

sub WriteSessionData(strSQL)
  on Error Resume next
  set oconn=Server.CreateObject("ADODB.Connection")
  oconn.open "DSN=IISLOGS_DSN;UID=anonymous;PWD=anonynous;"
  ocnn.Execute strSQL
  set oconn=Nothing
end sub

sub WriteSessionString(strEntry)
  strFileName="/logfiles/sessions.log"
  set objFSO=CreateObject("Scripting.FileSystemObject")
  'open the file with vbForAppending(8) and create if not existing
  set objFile=objFSO.OpenTextFile(strFileName,8,TRUE)
  objFile.WriteLine strEntry
  objFile.Close
end function

</script>
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
<script language="javascript">
<!--
var error Resume next
<%
var arrBooks=new Arry();
On Error resume next
set oconn=server.createObject("ADODB.connection")
oconn.open strConnect
strSQL="select ttitle from booklist order by tTitle"
set ors=oconn.Execute(strSQL)
intNumrecs=0
do while not ors.EOF
%>
arrBooks[<%=intNumrecs%>]="<%=ors("tTitle")%>";
<%
intNumrecs=intNumrecs+1
ors.MoveNext
loop
set ors=Nothing
set oconn=Nothing
%>

''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'启动一个窗口
<script language="javascript">
<!--
var objWin;
function openWindow()
{
  objWin=winow.open("pop_up_frame.htm","new_win","resizable=yes,"+
                    "scrollbars=no,toolbar=no,location=no,directories=no,status=no,"+
                    "menubar=no,width=180,height=235,top=5,left=5");
  objwintimer=window.setTimeOut("closeWinow()",60000);
}
function closeWindow()
{
objWin.close();
}
//-->
</script>
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'发邮件
Introduction
This article shows how to send email from an ASP page using CDONTS Component.

Code snippet
Sub send_email(email_from, email_to, email_subject, email_body)
    Dim Newmail
    Set Newmail = server.CreateObject ("cdonts.newmail")
   
    Newmail.BodyFormat = 0
    Newmail.MailFormat = 0
    Newmail.From = email_from
    Newmail.To = email_to
    Newmail.Subject = email_subject
    Newmail.Body = email_body
    Newmail.Send
   
    Set Newmail = Nothing   
End Sub


To call the procedure: Call send_email("from@domain.com","to@domain.com","Subject","Body")
If you have any difficulty using CDONTS, it is most often the configuration of the SMTP service on IIS. There is not much that can go wrong with this simple, yet extremely powerful component.

''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'图像计数器
<!--count.asp-->
<%option Explicit%>
<%response.buffer=true%>
<%
dim fso,f,i,counts,length
set fso=Server.createobject("script.FileSystemObject")
set f=fso.opentextfile(server.mappath("count.log"))
counts=Clng(f.readLine)
if session("counts")="" then
   session("counts")=counts
   f.close
   counts=counts+1
   set f=fso.createTextFile(server.mappath("count.log"),true)
   f.writeline(counts)
end if
f.close
length=Len(counts)
for i=1 to 8-length
    response.write "<img src=images/0.gif></img>"
next
for i=1 to length
    response.write "<img src="&"images/"&Mid(counts,i,1)&".gif></img>"
next
%>
<%server.Execute("count.asp")%>
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'发送电子邮件的CDONTS组件的NewMail对象
from属性:设置发件人的电子邮件地址
To属性:设置收件人的电子邮件地址
bcc属性:设置密件收件人的电子邮件地址
cc属性:设置抄件人的电子邮件地址
subject属性:主题
body属性:正文部分
bodyformat属性:确定邮件的格式是html或普通文本
contentbase属性:设置邮件正文的基地址
contentlocation属性:设置邮件的绝对或相对的url地址
importance属性:设置邮件的重要性
mailformat属性:设置邮件的格式是MIME类型还是普通文本
value属性:用来设置更多的电子邮件发送头
version属性:返回CDONTS组件的版本
AttachFile方法:附加一个文件
AttachURL方法:附加一个URL地址
send方法:发送电子邮件
setLocaleIDs方法:设置电子邮件的代码页供浏览者选用合适的编码

'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

面向对象编程的基本知识——类、对象(asp.net)

面向对象编程的基本知识——类、对象   1、类 “类”是面向对象编程(OOP)中最重要的概念之一。 所谓的面向对象编程就是指的所有信息都封装在类中,使用的时候通过某一个具体的类...

ASP加ACCESS数据的基本知识

入门经验谈 一.VBScript语法简介 VBScript语句是一种基于VB的一种脚本语言,主要用于WEB服务器端的程序开发,我们 这里只介绍一些简单的语句,主要是操作数据库的几种常见的语句...

第二章ASP基本知识之1 ASP概述

  • 2012年12月16日 22:16
  • 1.09MB
  • 下载

IOS和安卓ui设计常用尺寸及基本知识

https://wenku.baidu.com/view/18a745c4de80d4d8d05a4fbb.html IOS和安卓ui设计常用尺寸及基本知识 iOS app 图标的圆角半径...

Mongodb基本知识和常用语法

推荐阅读:《MongoDB:The Definitive Guide》 http://book.douban.com/subject/4746684/                      中文版...

Android UI设计常用尺寸及基本知识

屏幕尺寸 指实际的物理尺寸,为屏幕对角线的测量。 为了简单起见,Android把实际屏幕尺寸分为四个广义的大小:小,正常,大,特大。 像素(PX) 代表屏幕上一个物理的像素点代表屏幕上一个物理的...

SCO Unix常用命令及基本知识

SCO UNIX5 的引导过程基本可分为六步:   1、 PC机的BIOS将Master Boot Block 装入内存。(读取硬盘的Track 0 , Sector 0处的信息)   2、 Ma...
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:asp常用的一些基本知识
举报原因:
原因补充:

(最多只允许输入30个字)