如何从asp.net中的数据库中获取登录用户的记录? [英] how to get the record of a logged in user from database in asp.net?

查看:89
本文介绍了如何从asp.net中的数据库中获取登录用户的记录?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用asp.net。我正在努力开发:

1. asp.net中的登录页面,一旦用户输入正确的用户名和密码,这将被定向到用户页面。

2.在用户页面中,将有一些用户的文本字段(例如,名称和地址),所有这些都假设从SQL Server检索。在这里,如果在数据库中找到用户名,他/她的数据将显示在文本框中(例如,名称和地址),否则,文本框保持为空。用户可以选择在文本框中编辑或输入新数据并提交回数据库。

3.更新后,用户可以点击保存并注销保存数据并注销。

我已经完成了登录部分,但仅在(2)中,我不知道如何检索数据。知道如何根据用户的用户名检索数据吗?

谢谢。

Hi, I'm using asp.net. I am trying to develop:
1. a login page in asp.net, once user enter the correct username and password, this will be directed to the User page.
2. In User page, there will be some text fields of the user (eg. name and address), all these suppose to retrieve from SQL Server. In here, if the username is found in the database, his/her data will be displayed in the textboxes ( eg. name and address), if not, the textboxes remain empty. User can choose to edit or enter new data into the textboxes and submit back to the datadase.
3. Once updated, user can click "save and logout" to save the data and logout.
I've done the login part, but only in (2), I dont know how to retrive data. Any idea how to retrieve data based on user's username?
Thanks.

推荐答案

您可以将登录用户的UserId存储在会话如: -

会话[UserId] = userId;

否则如果您可以从用户名中检索,则直接使用userId。

You can store the UserId of the logged in user in a session like:-
Session["UserId"] = userId;
else if you can retreive from the username then use the userId directly.
SocialNetwork_DBEntities sn_DBEntities = new SocialNetwork_DBEntities();
var userDetails = sn_DBEntities.web_users.SingleOrDefault(x=>x.UserId==userId);



userDetails将记录登录用户的所有详细信息。

请添加其他方法并检查此代码。

请回复您的查询(如果有的话) 。

谢谢:)


The userDetails will contan all the details for the logged in user.
Please add another method and check for this code.
Please post back your queries if any.
Thanks:)


这篇关于如何从asp.net中的数据库中获取登录用户的记录?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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