ASP中Application与Sesstion对象的使用实例

1.Application使用实例 [特别提示:下面程序通常用作计数器]
Application是服务器端的变量,作用域是整个系统,不会因为客户端的不同而不同

Copy code
<html>
<head>
<title>Appliction使用实例</title>
</head>
<body>
<%
application("count")=application("count")+1
Response.Write("本页面已被刷新了"&application("count")&"次")
%>
</body>
</html>



2.Session使用实例 [特别提示:下面程序常用作身份验证]
运行过程:login.asp->check.asp->admin.asp
session是客户端的变量,作用域尽局限与一台电脑,它不会把他的值传递给服务器的
使用详解:http://icqc.cn/bbs/read.php?tid=387

下面这个是login.asp
Copy code
<%@LANGUAGE="VBSCRIPT" CODEPAGE="936"%>
<html>
<head>
<title>Session使用实例</title>
</head>
<body>
<%
session("Passed")=false
if session("head")="" then
session("head")="欢迎你管理员"
end if
%>
<%=session("Head")%>
<form action="check.asp" name="check" method="post">
用户名:<input type="text" name="ID" size="12">
密码:<input type="password" name="Pwd" size="12">
<input type="submit" value="登陆">
</form>
</body>
</html>



下面这个是check.asp
Copy code
<%
ID = Request("ID")
Pwd = Request("Pwd")

If ID = "" Or Pwd = "" Then
session("Head") = "请输入用户名与密码"
response.redirect "login.asp"
Else If ID = "admin" and Pwd = "admin" Then
session("Head") = ""
Session("Passed") = True
Response.Redirect "admin.asp"
Else
session("Head") = "用户名或密码错误!请重新输入!"
response.redirect "login.asp"
End If
%>



下面这个是admin.asp
Copy code
<%
if Session("Passed") = True then
Response.Write "你已经成功登陆!"
else
Response.Write "你没有权限进入本页面!"
Response.end
end if
%>
<%Response.Write "下面是管理页面的内容!"
Response.Write "<font color=red>欢迎到[url]www.icqc.cn/bbs[/url]来!</font>"
%>
posted @ 2008-05-16 18:49  天涯海客  阅读(264)  评论(0编辑  收藏  举报