如何使用C#中使用会话变量在ASP [英] how to use session variable in asp using c#

查看:104
本文介绍了如何使用C#中使用会话变量在ASP的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何我们的ASP.NET创建C#在登录页面会
给我完整的例子......

how we create session in login page in asp .net with c# give me full example......

推荐答案

假设你的code是在页面(内联或code后面),您可以只使用...

Assuming that your code is in the page (either inline or in the code behind) you can just use...

DataType someValue = (DataType)Session["SessionVariableNameHere"]; //Getter
Session["SessionVariableNameHere"] = someNewValue; //Setter

显然,你需要正确地命名您的会话变量,并转换为,当你把它找回来了会议的适当的数据类型。

Obviously you'll need to name your session variable properly, and cast to the appropriate data type when you get it back out of the session.

修改 - 一个完整的示例

EDIT - A Full Example

protected void Login1_LoggedIn(object sender, EventArgs e)
{
    Session["LoginTime"] = DateTime.Now;
}

和后来在页面加载...

and later in a page load...

protected void Page_Load(object sender, EventArgs e)
{
    Literal1.Text = "Last Online: " + ((DateTime)Session["LoginTime"]).ToString("yyyy-MM-dd");
}

这篇关于如何使用C#中使用会话变量在ASP的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆