asp常用的一些基本知识

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

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

<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 οnlοad="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方法:设置电子邮件的代码页供浏览者选用合适的编码

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值