楚
楚山孤
ASP快速入门(4)
下一步就是利用Select 语句列出所有的已知授权用户。此语句用Select Case开始,用End Select 结束。在这个语句里,我们将用户输入的用户名和我们已知授权用户的资料进行比较。如果用户输入的用户名和我们已经的授权用户中的任何一个用户名相符,则接着if-then语句则会判断特定的用户名所输入的密码是否正确。例如,如果用户输入了已知的授权用户名tim,则if-then 语句会判断输入的密码是否是bender。如果用户输入的用户名和密码资料都正确,则变量GrantAccess被赋值为true。如果用户输入的用户名不和任何一个已知授权用户名相符或者虽然用户名相符,但密码错时,则GrantAccess变量维持False不变。
在Select 语句之后,程序会检查GrantAccess的值。如果为true,则客户端的浏览器会被重定向(利用Response.Redirect方法)到另一个页面SecurePage.asp。如果用户输入的用户名和密码资料并不正确,也就是GrantAccess值为False时则客户端的浏览器会被重新导到上一个登陆页。
Of course, "SecurePage.asp" isn''t really too secure. If someone were to guess the URL, or if it were to be leaked out, the contents of that page would be readily available to anyone on the Internet. To shore up this security hole, we can modify the ending if-then statement in Example 2b to read:
当然,这里的所谓SecurePage.asp事实上并不太安全。如果有人能够猜出这个文件的URL,或者这个URL被人不小心泄露了出去,则任何人都可以在Internet上看到这个页面。为了解决这个安全问题,我们可以对上述代码的if-then语句进行修改 :
Example 2c (modified ending to ProcessLogin.asp):
If GrantAccess Then
Response.Cookies("LoggedIn") = "True"
Response.Redirect "SecurePage.asp"
Else
Response.Cookies("LoggedIn") = ""
Response.Cookies("LoggedIn").Expires =
"1/1/1980"
Response.Redirect "Login.htm"
End If
%>
在这里,如果用户输入的用户名和密码资料相符的话,在当前页面被重定向到下一个页面之后程序会利用Response.Cookies方法创建一个叫”LoggedIn”的cookie。
If the username and password doesn''t match up, the browser is sent back to the login page. For added security, any existing cookies are overwritten and destroyed (by setting the expiration date to a past date) just before the redirect. To further protect the secure page, we should start it with:
如果用户输入的用户名和密码资料并不正确,则浏览器会被直接重新导向前一个页面。另外为了更为安全起见,程序将已经存在的cookie值进行覆盖并使之过期(将功cookie的过期日期设为已经过去的时间)。然后我们需要在SecurePage.asp文件的头部加上以下代码:
Example 2d (beginning of SecurePage.asp):
以上代码的作用是在有任何HTML标记被送到浏览器前,程序会检查用户的cookie(利用Request.Cookies对象),并确认”LoggedIn”值是否为true。如果不是的话,则用户会被重新弹回上一页面。如果用户输入的数据为正确,则此句之后的HTML代码会被送到客户的浏览器上。
在这里请注意Request.Cookies 和 Response.Cookies。Request对象是用来接收用户浏览器端的数据的(例如cookie和提交的表单)。而Response对象则是用来送数据到用户浏览器的(例如,设置cookie和通知浏览器重定向位置)。
以上我们用例子简单地介绍了一下ASP。其实,在ASP里面还有许多强大的功能,比如说有内置的可以用来记录整个应用程序的数据的机制,有简单灵活的数据库应用接口,有方便的收发Email工具。在这里就不一一尽述了。总之,ASP是开发动态网页的好帮手,相信我,加入到ASP的世界吧。
下一步就是利用Select 语句列出所有的已知授权用户。此语句用Select Case开始,用End Select 结束。在这个语句里,我们将用户输入的用户名和我们已知授权用户的资料进行比较。如果用户输入的用户名和我们已经的授权用户中的任何一个用户名相符,则接着if-then语句则会判断特定的用户名所输入的密码是否正确。例如,如果用户输入了已知的授权用户名tim,则if-then 语句会判断输入的密码是否是bender。如果用户输入的用户名和密码资料都正确,则变量GrantAccess被赋值为true。如果用户输入的用户名不和任何一个已知授权用户名相符或者虽然用户名相符,但密码错时,则GrantAccess变量维持False不变。
在Select 语句之后,程序会检查GrantAccess的值。如果为true,则客户端的浏览器会被重定向(利用Response.Redirect方法)到另一个页面SecurePage.asp。如果用户输入的用户名和密码资料并不正确,也就是GrantAccess值为False时则客户端的浏览器会被重新导到上一个登陆页。
Of course, "SecurePage.asp" isn''t really too secure. If someone were to guess the URL, or if it were to be leaked out, the contents of that page would be readily available to anyone on the Internet. To shore up this security hole, we can modify the ending if-then statement in Example 2b to read:
当然,这里的所谓SecurePage.asp事实上并不太安全。如果有人能够猜出这个文件的URL,或者这个URL被人不小心泄露了出去,则任何人都可以在Internet上看到这个页面。为了解决这个安全问题,我们可以对上述代码的if-then语句进行修改 :
Example 2c (modified ending to ProcessLogin.asp):
If GrantAccess Then
Response.Cookies("LoggedIn") = "True"
Response.Redirect "SecurePage.asp"
Else
Response.Cookies("LoggedIn") = ""
Response.Cookies("LoggedIn").Expires =
"1/1/1980"
Response.Redirect "Login.htm"
End If
%>
在这里,如果用户输入的用户名和密码资料相符的话,在当前页面被重定向到下一个页面之后程序会利用Response.Cookies方法创建一个叫”LoggedIn”的cookie。
If the username and password doesn''t match up, the browser is sent back to the login page. For added security, any existing cookies are overwritten and destroyed (by setting the expiration date to a past date) just before the redirect. To further protect the secure page, we should start it with:
如果用户输入的用户名和密码资料并不正确,则浏览器会被直接重新导向前一个页面。另外为了更为安全起见,程序将已经存在的cookie值进行覆盖并使之过期(将功cookie的过期日期设为已经过去的时间)。然后我们需要在SecurePage.asp文件的头部加上以下代码:
Example 2d (beginning of SecurePage.asp):
以上代码的作用是在有任何HTML标记被送到浏览器前,程序会检查用户的cookie(利用Request.Cookies对象),并确认”LoggedIn”值是否为true。如果不是的话,则用户会被重新弹回上一页面。如果用户输入的数据为正确,则此句之后的HTML代码会被送到客户的浏览器上。
在这里请注意Request.Cookies 和 Response.Cookies。Request对象是用来接收用户浏览器端的数据的(例如cookie和提交的表单)。而Response对象则是用来送数据到用户浏览器的(例如,设置cookie和通知浏览器重定向位置)。
以上我们用例子简单地介绍了一下ASP。其实,在ASP里面还有许多强大的功能,比如说有内置的可以用来记录整个应用程序的数据的机制,有简单灵活的数据库应用接口,有方便的收发Email工具。在这里就不一一尽述了。总之,ASP是开发动态网页的好帮手,相信我,加入到ASP的世界吧。