如何在用户登录后识别用户 [英] How to recognise a user once he logs in

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

问题描述

我使用ASP.NET设计了一个网站。我的网站连接到Oracle。我使用自己的登录来检查用户名和密码。用户需要输入他/她的ID。一旦他或她输入有效输入,他/她就会被重定向到MasterPage。我的问题是如何识别用户名,因为数据库中链接到登录页面的表具有属性ID,NAME,PASSWORD和E-MAIL。一旦他/她登录,我想用他/她的名字识别用户。像欢迎MR.X而不是欢迎MR.1244。请帮我。我搜索了很多,但我无法解决它。谢谢

I have designed a website using ASP.NET. My website connects to Oracle. I used my own login that checks if username and password. The user is required to enter his/her ID. Once he or she enters a valid input, he/she is redirected to MasterPage. My problem is how i can recognise the User's name because the table in the database that links to login page have attributes ID,NAME,PASSWORD and E-MAIL. I wanted to recognise the user by his/her name once he/she login .Something like "Welcome MR.X" Instead of "Welcome MR. 1234". Please help me. I have searched a lot but i couldn't solution for it. Thanks

推荐答案

首先,为什么要重新发明轮子?为什么创建自己的登录系统(看起来你不明白),当有一个已经建立和证明? 会员资格简介 [ ^ ]引导您完成...并为您保护您的网站,您的系统需要不断检查!



其次,我们不能确切 - 毕竟你创建了自己的系统,所以我们不知道你使用了什么代码或者有什么组织。 />
但是......您使用欢迎MR.1234意味着您正在登录用户,并在某处(可能在会话中或通过Cookie)存储用户ID值。因此,您在页面加载中所要做的就是使用该ID值从数据库中获取行:

First off, why did you reinvent the wheel? Why create your own login system (which it would appear you don't understand) when there is one already built and proven? Introduction To Membership[^] guides you through...and it secures your web site for you, where your system requires constant checking!

Secondly, We can't be precise - you created your own system, after all so we don't know what code you used or how anything is organised.
But...your use of "Welcome MR. 1234" implies that you are logging the user in, and storing the user ID value somewhere, probably in the Session or via Cookies. So all you have to do in your page load is use that ID value to get the row from your DB:
SELECT name FROM MyTable WHERE Id=1234

可能会这样做虽然你想用实际值替换样本id,但很明显。

或者,当你存储ID时,也存储名称?

would probably do it although you'd want to replace the sample id with the actual value, obviously)
Alternatively, when you store the ID, store the Name as well?


您需要使用用户在登录时输入的凭据(用户名和密码)查询数据库。



从数据库获取名称和其他详细信息后,使用Session来存储它们。



现在,您可以在任何页面上的应用程序内的任何位置访问会话值,这将反映用户的详细信息。
You need to query to the database using the credentials (username and password) entered by user while logging in.

After you got the name and other details from database, just use Session to store them.

Now, you can access the Session values anywhere inside the application on any page, which will reflect user details.


这篇关于如何在用户登录后识别用户的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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