Overview:
The Session Object is how you track a single user across many pages. It has four (4) properties, two (2) collections, one (1) method, and two (2) events.
Get Started:
In this series of examples we will create a password system. We will use the Session Object to track whether or not a user is authorized to view certain pages. Below are several scripts for lesson12. Look at them, play with, and then read the explanations that come further down the page.
<%@LANGUAGE="JavaScript"%> <% //No ASP Here, just a regular HTML Page %> <HTML> To play along with our password page, put in a user name and a password.<BR> <BR>The correct user name is <I>guest</I>.<BR> And the correct password is also <I>guest</I>.<BR> <FORM METHOD="post" ACTION="script12a.asp"> User:<INPUT TYPE="text" SIZE="9" NAME="userName" VALUE="guest"><BR> Pass:<INPUT TYPE="password" SIZE="9" NAME="userPassword" VALUE="guest"> <BR> <INPUT TYPE="submit" value="Login"> </FORM> </HTML>
Click Here to run script12.asp in a new window. Below is script12a.asp.
<%@LANGUAGE="JavaScript"%> <% var userName=new String(Request.Form("userName")) var userPassword=new String(Request.Form("userPassword")) if (userName=="guest" && userPassword=="guest") { Session("Authorized")=true Response.Redirect("script12b.asp") } else { Session("Authorized")=false %> <HTML> You did not supply the correct Name & Password.<BR> <A HREF="script12.asp">Click here</A> to log in. </HTML> <% } //end else statement %>
We'll skip over script12b.asp entirely because it's almost exactly the same as script12c.asp. Down below is script12c.asp.
<%@LANGUAGE="JavaScript"%> <% if (Session("Authorized")!=true) { %> <HTML> You are not an authorized user.<BR> <A HREF="script12.asp">Click here</A> to log in. </HTML> <% } else { %> <HTML> The <B>second</B> of two pages that are password protected.<BR> <A HREF="script12d.asp">Click Here</A> to log out. </HTML> <% } //end of else statement %>
Above is script12c.asp, which is the second of two password-protected pages. Below is script12.asp, which is the logout page.
<%@LANGUAGE="JavaScript"%> <% if (Session("Authorized")!=true) { %> <HTML> You are not an authorized user.<BR> <A HREF="script12.asp">Click here</A> to log in. </HTML> <% } else { var SessionID=Session.SessionID Session.Abandon() %> <HTML> You have sucessfully logged out.<BR> This was session <%=SessionID%>.<BR><BR> Now try a link to one of the pages you've already visited.<BR><BR> <A HREF="script12b.asp">script12b.asp</A><BR> <A HREF="script12c.asp">script12c.asp</A><BR> <A HREF="script12d.asp">script12d.asp</A><BR> </HTML> <% } //end of else statement %>
A Quick Explanation:
After all that, the last thing you want to see is another grey box full of code. Sorry to do it one more time but, the keystone to this system is in script12a.asp. I've reprinted it down below.
if (userName=="guest" && userPassword=="guest") { Session("Authorized")=true Response.Redirect("script12b.asp") }
Any page can now be turned into a password protected page with the following line:
Session Collections:
The two Session Collections are Session.Contents and Session.StaticObjects. They parallel the Application.Contents and Application.StaticObjects.
Using
The shortcut is what you saw in the scripts above.
Session.Contents has two methods of its own. They are
We did not demonstrate StaticObjects in the scripts above. It comes in the form of the <OBJECT> flag (set for Session scope).
No Sharing:
Remember how Application variables could be shared by all viewers on your ASP web site? That's not so with Session Variables. They are private; Session Variables are to be accessed only by one user.
Session.Abandon( ):
My bet is you could figure out Session.Abandon() without any explanation. However, let me just state for the record that Session.Abandon() ends the user's session and releases the Session Variables from memory.
Session Properties:
Let's briefly discuss two properties you are not likely to use. Session.CodePage lets you call for foreign character sets, like Chinese or Russian. Session.LCID is a location identifier. It determines the time zone and language for the server. Don't mess with it.
Now let's move on to something you might actually use from time to time. Session.SessionID is a read-only property generated by the server, and assigned to one specific user during one specific session. The SessionID follows the user from the beginning of the session until the end.
Session.Timeout is the number of minutes that a user can be idle before the Server ends the user's individual session and reclaims the memory that was allocated to Session Variables. (Session.Timeout is demonstrated in the global.asa in lesson 10.)
Session Events:
The two Session events are Session_OnStart() and Session_OnEnd(). These events are accessed in the global.asa. You can see an example of global.asa in lesson 10.
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件! 如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
RTX 5090要首发 性能要翻倍!三星展示GDDR7显存
三星在GTC上展示了专为下一代游戏GPU设计的GDDR7内存。
首次推出的GDDR7内存模块密度为16GB,每个模块容量为2GB。其速度预设为32 Gbps(PAM3),但也可以降至28 Gbps,以提高产量和初始阶段的整体性能和成本效益。
据三星表示,GDDR7内存的能效将提高20%,同时工作电压仅为1.1V,低于标准的1.2V。通过采用更新的封装材料和优化的电路设计,使得在高速运行时的发热量降低,GDDR7的热阻比GDDR6降低了70%。
更新日志
- 群星.1995-坠入情网【宝丽金】【WAV+CUE】
- 群星《谁杀死了Hi-Fi音乐》涂鸦精品 [WAV+CUE][1G]
- 群星1998《宝丽金最精彩98》香港首版[WAV+CUE][1G]
- 汪峰《也许我可以无视死亡》星文[WAV+CUE][1G]
- 李嘉-1991《国语转调2》[天王唱片][WAV整轨]
- 蔡琴2008《金声回忆录101》6CD[环星唱片][WAV整轨]
- 群星《2024好听新歌36》AI调整音效【WAV分轨】
- 梁朝伟.1986-朦胧夜雨裡(华星40经典)【华星】【WAV+CUE】
- 方芳.1996-得意洋洋【中唱】【WAV+CUE】
- 辛欣.2001-放120个心【上海音像】【WAV+CUE】
- 柏菲·万山红《花开原野1》限量开盘母带ORMCD[低速原抓WAV+CUE]
- 柏菲·万山红《花开原野2》限量开盘母带ORMCD[低速原抓WAV+CUE]
- 潘安邦《思念精选集全纪录》5CD[WAV+CUE]
- 杨千嬅《千嬅新唱金牌金曲》金牌娱乐 [WAV+CUE][985M]
- 杨钰莹《依然情深》首版[WAV+CUE][1G]