使用自定义成员资格提供程序时,在 ASP.NET 中推荐的用户特定持久变量存储方法是什么?
我有一个 ASP.NET 应用程序,它使用自定义 MembershipProvider 来允许用户登录并访问某些功能。 MembershipProvider 使用 ASP.NET 的内置表单身份验证来设置 cookie 并跟踪用户是谁。
现在我已经让用户登录了,存储会话的用户特定信息的最佳方法是什么?过去我只使用会话变量,即 Session["ReputationLevel"] = "4230";
(我的应用程序实际上没有信誉级别变量,这只是一个示例)。使用 MembershipProvider 时这仍然是最好的方法吗?以某种方式将此信息构建到提供程序本身中,还是构建到自定义 MembershipUser 实现中会更好吗?如果我将所有内容保留在会话中,我想当 MembershipProvider 指示用户已注销时我必须放弃会话......?
抱歉,如果这个问题含糊不清。过去几年我主要从事 ColdFusion 开发,但对于其中一些 ASP.NET 技术还是比较陌生。我认为 MembershipProvider 功能可以满足我需要的一切,但我现在发现我的实现中仍然存在一些漏洞(在本例中,在哪里存储附加数据)。
这个问题似乎类似,但没有出现正是我所要求的。
I have an ASP.NET application that uses a custom MembershipProvider to allow users to log in and gain access to certain features. The MembershipProvider uses ASP.NET's built-in forms authentication to set cookies and keep track of who the user is.
Now that I've got the user logged in, what's the best way to store user-specific information for their session? In the past I've just used Session variables ie Session["ReputationLevel"] = "4230";
(my application doesn't actually have a reputation level variable, this is just an example). Is this still the best way when using a MembershipProvider? Would it be better to somehow build this information into the provider itself, or into a custom MembershipUser implementation? If I keep everything in the session, I suppose I'd have to abandon the session when the MembershipProvider indicates that the user had logged out...?
Sorry if this question is vague. I've been doing mostly ColdFusion development for the past few years, and I'm still kinda new to some of these ASP.NET technologies. I thought the MembershipProvider functionality would take care of everything I needed, but I'm now seeing there are still some holes in my implementation (in this case, where to store additional data).
This question appears to be similar, but doesn't appear to be quite what I'm asking.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您想在会话之外保留信息,最好按用户将其存储在数据库中。有几种方法可以做到这一点:
If you want to persist the information beyond the session, it's probably best to store it by user in your database. There are several ways to do this:
我不确定你会如何做到这一点,但我想你可以扩展会员资格提供程序来做到这一点。但就我个人而言,我发现普通会议效果很好。我唯一要做的就是将它们的功能包装在一组共享函数中。所以你的例子是:
只需调用
GetUserReputation
I'm not sure how you would do it, but I suppose you could extend the Membership provider to do that. But personally, I've found that ordinary sessions work just fine. Only thing I'd do is to wrap their functionality in a a set of shared functions. So your example would be:
and just call
GetUserReputation