Learning Purpose: Learn the use of SESSION and COOKIE
SESSION and COOKIE are used to pass variables between various web pages and to record user login information. Using COOKIE in ASP.NET is a little bit more troublesome than in ASP, because we want to declare variables.
First, let’s take a look at the use of SESSION, which is basically the same as ASP
Write a SESSION:
Session["username"])="aa";
Session("username")="aa"
Read a SESSINN:
string username= Session["username"];
dim username=Session("username")
Let’s take a look at COOKIE’s writing:
DateTime dt=DateTime.Now; // Need <%@Import Namespace="System"%> to get the current time
HttpCookie mycookie=new HttpCookie("logname");//Declare the new COOKIE variable
mycookie.Value="aa";//Assignment
mycookie.Expires=Convert.ToDateTime(dt+TimeSpan.FromDays(1));//Set the expiration time to 1 day
Response.Cookies.Add(mycookie1);//Write to COOKIE
dim dt as DateTime
dt=DataTime.Now
dim mycookie as HttpCookie
mycookie=new HttpCookie("logname")
mycookie.Value="aa"
mycookie.Expires=Convert.ToDateTime(dt+TimeSpan.FromDays(1))
Response.Cookies.Add(mycookie1)
Take a look at COOKIE reading:
HttpCookie mycookie=Request.Cookies["username"];
string username=mycookie.Value;
dim mycookie as HttpCookie
mycookie=Request.Cookies["username"]
dim string=mycookie.Value
At this point, "Ten Days Learning ASP.NET" is over. Time is in a hurry. Please forgive me for the incomplete writing. In fact, I just take you into the introduction. Learning depends on yourself.