如何在每个插入查询中插入用户ID [英] How to insert User ID in each insert query

查看:93
本文介绍了如何在每个插入查询中插入用户ID的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨.登录到我的应用程序后,我希望所有条目,记录插入均由已登录的用户ID进行保存.我已经在所有表中将UserID创建为FK.

Hi. After logging into my application, i want that all the entries, record insertion is made the logged in user ID is also save with that. I have created UserID as FK in all the tables.

我认为是什么?登录后,我将用户ID存储在单独模块中的全局变量中,然后在所有表单插入查询中使用该ID吗?但是问题是,如果登录的用户超过1个,那么如何维护该单个变量 因为如果登录了10个用户,那么我是否必须创建10个全局变量,然后登录100个用户.

What I think is After logging in, I will store the User ID in a global variable in a separate module and then I will use that ID in all the forms insert queries? But the problem is that if more than 1 users are logged in so how to maintain that single variable because if 10 users are logged in so Do I have to create 10 global variables and if 100 users are logged in then.

但这是我的软弱思维,完全不专业;我知道必须有一些更好的方法来完成此操作.

But this is my weak thinking, totally unprofessional; I know that there must be some better way to do this thing.

请指导我如何克服这个问题,这是我实际上正在从事的第一个项目.为此,请指导我.

Guide me please that how would I overcome this issue, this is my first project that I am practically working upon. Please guide me for this.

推荐答案

你好

一个选项是使用System.DirectoryServices.AccountManagement.PrincipleContext或System.Security.Principle.WindowIdentity.两者都可以从ActiveDirectory工作.另一个选择是使用数据库表中的主键存储每个用户的登录信息 谁登录到应用程序.

One option is to use System.DirectoryServices.AccountManagement.PrincipleContext or System.Security.Principle.WindowIdentity. Both work from ActiveDirectory. Another option is use the primary key in the database table storing login information for each user who logs in to the application.

使用Active Directory的优点是非常安全,但是如果操作正确(可能被视为缺点),则开发人员无权对其进行配置(我们向工程师提出要求,他们会实施更改).在这种情况下 无需在大多数情况下将用户信息存储在变量中.

Advantages of working with Active Directory is this is very secure but when done right (may be seen as a disadvantage) the developer does not have rights to configure it (we make request to our engineers and they implement the changes). In this case there is no need to store (in most cases) user information in variables.

使用登录主键的优点是易于实现,但通常不如活动目录安全.在这里,我们需要存储每个用户会话的用户信息,而全局上每个会话都适用,因此您无需存储 一个变量(例如List(Of UserInformation)

Advantage using login primary key is this is easy to implement but generally less secure then active directory. Here we need to store their user information per user session while globally the same holds true for each session so you would not be storing all users in one variable (such as a List(Of UserInformation)


这篇关于如何在每个插入查询中插入用户ID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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