如何在ASP登录页面中使用会话? [英] how to use session in asp log in page?

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

问题描述

告诉我登录时如何使用会话控制各种用户

hi tell me how to use session to control various user while login

推荐答案

object o = Session["nameOfVariable"];


您要如何处理会话和登录?您正在使用成员资格提供程序吗?


What are you trying to do with the session and login? Are you using a Membership Provider?


在登录页面中,您可以在检查用户提供正确的用户名和密码后创建会话.

In the login page you can create a session after checking the user has provided the correct username and pasword

Session["username"] = txt_username.Text;
Session["password"] = txt_password.Text;




之后,在每个页面中,您需要检查用户是否已登录,可以通过检查会话值来执行此操作.因此,在只有登录用户才能看到的每个页面加载事件中编写以下代码.




There after in every page you need to check if the user has been logged in or not , you can do this by checking the session values. So write the following code in every page load event which only logged in users should see.

if(Session["username"] == null || Session["password"]== null)
{
Response.Redirect("Login.aspx");
}
else
{
// You can write your desired code here

}





这只是一个lgin过程的小例子.您应该实施适当的方法来避免诸如SQL注入之类的安全漏洞.

希望这对您有所帮助.

如有任何疑问,请通知我.





This is just a small example for lgin process. You should implement proper methods to avoid security breaches like SQL injection and others.

Hope this will help you out.

Let me know in case of any doubts.


将建议您首先阅读本文
在ASP.Net中浏览会话 [ ^ ].这将使您对ASP.NET会话有足够的了解.之后,如果您有任何疑问,请告诉我们.
Will suggest you to Read this article first
Exploring Session in ASP.Net[^]. This will give you enough idea about ASP.NET Session. After that if you have any question do let us know.


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

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