[英]How to store information of logged in User in desktop application using c#
We want to keep track of which User is logged in at the moment. 我们要跟踪当前登录的用户。 Instead uf using for example: Environment.Username we want to know the Username from our database.
取而代之的是,例如,uf使用例如:Environment.Username我们想从数据库中知道用户名。 We are able to get the Username from the database but we want to store it somewhere.
我们可以从数据库中获取用户名,但是我们希望将其存储在某个地方。 Any solutions?
有什么办法吗?
An example from the question linked below: 来自下面链接的问题的示例:
Settings.Default["SomeProperty"] = "Some Value";
Settings.Default [“ SomeProperty”] =“某些值”;
Settings.Default.Save();Settings.Default.Save(); // Saves settings in application configuration file
//将设置保存在应用程序配置文件中
I recommend to have a glance at this question . 我建议看一下这个问题 。
Best practice to save application settings. 保存应用程序设置的最佳实践。 There are other solutions as well.
还有其他解决方案。
They are several solutions: 它们是几种解决方案:
Using MVVM, create shared user manager service(recommended). 使用MVVM,创建共享的用户管理器服务(推荐)。
Singleton service. 单例服务。
Application settings. 应用程序设置。
Static variable. 静态变量。
如果您的应用程序由多个用户使用,则您可以将数据存储在CSV,XML等传统文件中。但是,使用这种技术可能无法获得数据安全性,因此可以使用二进制序列化。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.