用于将当前用户数据存储在当前会话中的全局变量

时间:2022-12-08 11:14:45

last time I was checking about variables in asp.net, I have read that I should refrain using session variables, actually there's even an article talking about "session variable addicts" (:

上次我在asp.net中检查变量时,我已经读过我应该避免使用会话变量,实际上甚至有一篇文章谈论“会话变量上瘾者”(:

I am still fresh web developer , and my situation is :

我仍然是新鲜的Web开发人员,我的情况是:

  1. user enter application
  2. 用户输入申请
  3. page load: I check cookies - if cookie exist = welcome the user.

    页面加载:我检查cookie - 如果cookie存在=欢迎用户。

    if no cookie - hand the user a proper registration form

    如果没有cookie - 给用户一个正确的注册表

  4. user submits form - store user in cookies . set new record in database

    用户提交表单 - 将用户存储在cookie中。在数据库中设置新记录

ok so now there is a question, from this moment and until user has exited the application

好的,现在有一个问题,从这一刻起,直到用户退出应用程序

for every request from this stage after cookie was set,

在设置cookie之后,对于此阶段的每个请求,

what am I suppose to choose:

我想要选择什么:

  1. check in every post if cookie exist
  2. 如果存在cookie,请检查每个帖子
  3. store user data in session and read from it on next click
  4. 在会话中存储用户数据,并在下次单击时从中读取
  5. no need to / none of the above
  6. 不需要/没有以上

I will appreciate the correct informing answer ! thanks.

我将非常感谢正确的通知答案!谢谢。

1 个解决方案

#1


1  

In my experience, the ASP.NET membership provider works well for both user authentication as well as storing user profile data. You can create a customer user profile object that stores user information/preferences (basically, any data unique to each user) that is then stored in the database and can be retrieved the next time the user logs on.

根据我的经验,ASP.NET成员资格提供程序适用于用户身份验证以及存储用户配置文件数据。您可以创建一个客户用户配置文件对象,该对象存储用户信息/首选项(基本上是每个用户唯一的任何数据),然后存储在数据库中,并在下次用户登录时检索。

See the following link from Microsoft: http://msdn.microsoft.com/en-us/library/yh26yfzy(v=vs.100).aspx

请参阅Microsoft的以下链接:http://msdn.microsoft.com/en-us/library/yh26yfzy(v=vs.100).aspx

And see the following about writing a custom profile class: http://weblogs.asp.net/jgalloway/archive/2008/01/19/writing-a-custom-asp-net-profile-class.aspx

请参阅以下有关编写自定义配置文件类的信息:http://weblogs.asp.net/jgalloway/archive/2008/01/19/writing-a-custom-asp-net-profile-class.aspx

#1


1  

In my experience, the ASP.NET membership provider works well for both user authentication as well as storing user profile data. You can create a customer user profile object that stores user information/preferences (basically, any data unique to each user) that is then stored in the database and can be retrieved the next time the user logs on.

根据我的经验,ASP.NET成员资格提供程序适用于用户身份验证以及存储用户配置文件数据。您可以创建一个客户用户配置文件对象,该对象存储用户信息/首选项(基本上是每个用户唯一的任何数据),然后存储在数据库中,并在下次用户登录时检索。

See the following link from Microsoft: http://msdn.microsoft.com/en-us/library/yh26yfzy(v=vs.100).aspx

请参阅Microsoft的以下链接:http://msdn.microsoft.com/en-us/library/yh26yfzy(v=vs.100).aspx

And see the following about writing a custom profile class: http://weblogs.asp.net/jgalloway/archive/2008/01/19/writing-a-custom-asp-net-profile-class.aspx

请参阅以下有关编写自定义配置文件类的信息:http://weblogs.asp.net/jgalloway/archive/2008/01/19/writing-a-custom-asp-net-profile-class.aspx