10 days to learn the ASP.net day

Source: Internet
Author: User
ASP.net learning Purpose: Learn the session and use of cookies

In the various pages of the variable transmission and some record user login information to use session and cookies. Using cookies in asp.net is a bit more cumbersome than ASP, because we want to declare variables.

First look at the use of the session, basic and ASP almost
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 the writing of the cookie:
DateTime Dt=datetime.now; Need to <% @Import namespace= "System"%&gt, to get the current time
HttpCookie mycookie=new HttpCookie ("logname");/declare new cookie variable
MyCookie. Value= "AA";//Assign Value
MyCookie. Expires=convert.todatetime (Dt+timespan.fromdays (1));/set expiration time of 1 days
RESPONSE.COOKIES.ADD (MYCOOKIE1);//write 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)

Look at the read of the cookie:

HttpCookie mycookie=request.cookies["username"];
String Username=mycookie. Value;


--------------------------------------------------------------------------------


Dim MyCookie As HttpCookie
mycookie=request.cookies["username"]
Dim String=mycookie. Value

To this "Ten days to learn asp.net" end, time is hasty, but also please forgive write incomplete, in fact, I just take you to get started, learn to rely on their own AH.


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.