简体   繁体   English

会话-登录以查看用户数据

[英]Session - Login to view user data

Before I start I would like to state that I am very VERY new to ASP.NET and C#, and programming in general really. 在开始之前,我想指出一下,我对ASP.NET和C#非常陌生,并且实际上对程序设计真的很熟悉。 I have created a web application with a login page looking to a custom database containing the user's data as well as their login details. 我已经创建了一个带有登录页面的Web应用程序,该页面查找包含用户数据及其登录详细信息的自定义数据库。 I did this rather than using the ASP.NET Membership as there are complications using this over my college's network. 我这样做不是使用ASP.NET成员资格,因为在我的大学网络中使用它会带来一些麻烦。

As the table contains many records of user data, what I would like to do is have a user log into the app and (based on their login details) allow them to view JUST their details from the table I have created as their are many records of user data. 由于该表包含许多用户数据记录,因此我想做的是让一个用户登录到应用程序,并(基于他们的登录详细信息)允许他们仅从我创建的表中查看其详细信息,因为它们有很多记录用户数据。

Am I correct that I should create a session based on their username and password and with this, somehow match it to their record in the table using SQL which will display ONLY their data rather than the whole table be displayed? 我是否正确,我应该根据他们的用户名和密码创建一个会话,并以此方式以某种方式使用SQL将其与表中的记录进行匹配,从而只显示其数据,而不显示整个表?

If this is the case, I really don't have a clue how to implement this. 如果是这种情况,我真的不知道如何实现。

I am aware that this will be very insecure but the users are all fictional and this app will not be published to the web. 我知道这将是非常不安全的,但是用户都是虚构的,因此该应用程序不会发布到网络上。 I just want it to work in the simplest form for my assignment and I'll cover the security aspects in my report and state how it could be improved. 我只是希望它以最简单的形式进行分配,我将在报告中介绍安全方面并说明如何进行改进。

Any advice would be greatly appreciated, Cheers. 任何建议将不胜感激,干杯。

Whenever you find a user's credentials valid enough for login, add some/all of his credentials to the current session like, 每当您发现用户的凭据足以进行登录时,请将其部分/全部凭据添加到当前会话中,例如,

Session.Add("sessionvariablename",textBoxLogin.Text);

On the other page, that comes after logging in, check the following, 在登录后的另一页上,检查以下内容,

if(Session["sessionvariablename"].ToString()=="xyz")
{
Do whatever you want
}

You may not want to add sensitive information to the session for security concerns. 您可能不想出于安全考虑将敏感信息添加到会话中。 Use Guid.NewGuid() to create a unique 32 character hexadecimal code for each user and store it in session. 使用Guid.NewGuid()为每个用户创建一个唯一的32个字符的十六进制代码,并将其存储在会话中。

If I'm getting it right, using username and password as session parameters will work but it's not the best idea. 如果我做对了,可以使用用户名和密码作为会话参数,但这不是最好的主意。 Normally you table with users contains a kind of unique identifier for each record (guid or autoincrement id). 通常,与用户一起使用的表包含每个记录的一种唯一标识符(引导或自动增量ID)。 You may use this identifier as a session parameter. 您可以将此标识符用作会话参数。

You should have row in your table with with a unique identifier. 您的表中的行应带有唯一标识符。 Like ID or userNr or something similar, make it an integer and set to primary key and then set its identity specification (is identity) to yes by double clicking on it (I am presuming that you are using visual studio). 像ID或userNr或类似的东西,将其设置为整数并设置为主键,然后通过双击它的身份规范(即identity)将其设置为yes(我假设您正在使用Visual Studio)。

When the user has submitted there login info and they checked out, you save there unique identifier in a session. 当用户提交登录信息并签出后,您将在会话中保存唯一标识符。

when you need to pull out information specific to the user in question, you use sql WHERE ID (or userNr) is equal to the session id. 当您需要提取特定于该用户的信息时,可以使用sql WHERE ID(或userNr)等于会话ID。

hope this is what you needed, its my first answer in here so I would like to be helpful. 希望这是您所需要的,这是我在这里的第一个答案,因此我希望对您有所帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM