码迷,mamicode.com
首页 > 其他好文 > 详细

Session

时间:2017-08-07 20:30:27      阅读:102      评论:0      收藏:0      [点我收藏+]

标签:输入   sel   page   protected   用户   class   uname   log   对象   

Session

保存在服务器上
很安全
占用服务器资源
只有会话模式   20分钟生命周期
可以存任意数据类型,Object,取的时候需要类型转换
服务器内存

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class Default1 : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        Button1.Click += Button1_Click;
    }

    void Button1_Click(object sender, EventArgs e)
    {
        string uname = TextBox1.Text;//获取用户输入的用户名   
        string pwd = TextBox2.Text;//获取用户输入的密码
        Users u = new UsersData().SelectUser(uname, pwd);
        Session["hehe"] = u;//传值
        Response.Redirect("Default5.aspx");//跳到Default5.aspx
    }
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class Default5 : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Session["hehe"] != null)//不为空的时候执行
            Label1.Text = (Session["hehe"] as Users).NickName;//接受传过来的值  Session["hehe"] as Users变成对象
    }
}

 

Session

标签:输入   sel   page   protected   用户   class   uname   log   对象   

原文地址:http://www.cnblogs.com/skyhorseyk/p/7299544.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!