将用户会话信息添加到 HTTPContext
我现在有一个用户类,我想将该类添加到 HTTPContext 对象,以便每次发送请求时我不必验证它
I am Having a User Class now i want to add that class to HTTPContext object so that each time i send a request I don't have to validate it
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
ASP.NET 有多种状态管理方法 - 您需要选择最适合您需要的一种,然后仅存储一次经过验证的用户凭据。
如果您只有一个服务器设置,并且将来看不到对多个服务器/网络场的需求,您可以考虑使用 ASP.NET 会话状态。
会话状态使用服务器上的进程内内存 - 因此,如果您将请求分散到多个服务器,则此方法将不起作用。然后,您可以考虑在数据库中存储身份验证令牌。您可以混合使用两者 - 在数据库中存储会话状态。
最后,您可以考虑使用 ASP.NET Membership,它可以简化工作创建和管理用户、身份验证和授权。
ASP.NET has several state management approaches - you need to choose the one most suitable to your need, and then store your validated user credentials once only.
If you have a single server setup, and can't see the need for multiple servers / a web farm in the future, you could consider using ASP.NET Session State.
Session State uses in-process memory on the server - so if you are spreading requests to multiple servers, this approach won't work. You would then consider storing an authentication token in your database. You can have a mixture of the two - storing session state in the database.
Lastly, you could consider using ASP.NET Membership, which simplifies the job of creating and managing users, authentication, and authorization.