作者:仙人掌工作室
四、在安全页面中检查是否已经验证用户身份
每一个受保护的页面都应该检查用户身份是否已经验证。这是因为用户有可能为
这些页面做了书签,如果不在这些页面中验证用户已经登录,就不能保证浏览页面的
是经过授权的合法用户。
为检查是否已经验证用户身份,可以测试在signuseron中创建的session
("user")是否是一个对象、类型是否正确等。如果上述测试失败,则重定向到
登录页面signon.。对于不支持cookies的浏览器,检查用户是否经过身份验证的
方法略为复杂,它需要通过在application("users")中搜索id获得当前用户记录。
如下面的代码在signedon页面中完成上述检验:
< %@ language=vbscript %>
< % option explicit %>
< % response.buffer = true %>
< % response.expires = 0 %>
< !-- #include file="aspsecurity.inc" -->
< html>
< body>
< %
dim id
dim auser
dim appusers
dim authenticated
dim i
if session("supportscookies") then
if not isuser(session("user")) then
response.redirect "signon.asp"
else
set auser = session("user")
end if
else
authenticated = false
id = request("id")
if len(id) > 0 then
appusers = application("users")
for each auser in appusers
if auser("sessionid") = id then
authenticated=true
auser("lastactivity") = now()
application.lock
application("users") = appusers
application.unlock
exit for
end if
next
end if
if not authenticated then
response.redirect "signon.asp"
end if
end if
%>
您可能感兴趣的文章:
如您对本文有疑问或者有任何想说的,请点击进行留言回复,万千网友为您解惑!
网友评论