如何在登录页面中使用c sharp代码在asp.net中使用会话 [英] how to use sessions in asp.net using c sharp code in a login page

查看:56
本文介绍了如何在登录页面中使用c sharp代码在asp.net中使用会话的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

任何人都可以给我一个使用会话的登录页面示例,以及如何在登录页面以及整个项目中实现会话

提前感谢

Hi can Anybody give me an example for login page using sessions and how to implement sessions in login page and as well in the whole project
thanks in advance

推荐答案

去这里选择一个合适的教程:



http://www.asp.net/web-forms [ ^ ]
Go here and pick an appropriate tutorial:

http://www.asp.net/web-forms[^]


使用Session的建议和示例已经发布了很多次。在这里提问之前至少花几分钟做一些研究。



无论如何,从代码背后添加你的价值:



Session.Add(key,value);



和取回它:



对象值=会话[密钥];



这应该让你去。
Advice and examples of using Session have been posted many, many times. Before asking a question here at least spend a few minutes doing some research.

Anyway, from code behind add your value as:

Session.Add("key", "value");

and get it back as:

object value = Session["key"];

That should get you going.


protected void btnlogin_Click(objec sender,EventArgs e)
{
Userclass u=new Userclass();
u.Username=txtusername.text.trim();
u.Password=txtpassword.text.trim();
if(u.checkUser())
{
Session["youreSessionName"]=u.Username;
Response.redirect("./Home.aspx")

}
else
{
lblIsUser.text=" User DOes not Exist";
}





您将使用session [yoursessioname]作为项目中的用户名,以获取有关已记录的其他信息来自数据库或某处的用户



you will use session["yoursessioname"] as a user name in the project for other information about the logged user from database or somewhere


这篇关于如何在登录页面中使用c sharp代码在asp.net中使用会话的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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