即使不使用session存储数据也要保留sessionId吗?
嗨,
我正在构建一个 ASP.NET MVC 2 网站,需要将当前用户/会话绑定到一些数据。以下是可能的解决方案,但最佳实践是什么?
- 创建一个 GUID 并将其设置为视图中的隐藏字段,然后数据将保存在单个对象中(如缓存)。然而,安全性并不是最好的(用户可以更改隐藏字段的值)。
- 使用Session.SessionId。为了在调用之间保持相同的 SessionId 我需要在会话中存储一些东西,这感觉不对吗?我不确定这里是否存在任何安全问题?
BestRegards
我的解决方案: 我最终为当前客户创建了一个 GUID,然后将其设置为表单上的隐藏字段。然而,我确实遇到了一些问题,无法正确渲染隐藏字段,请参阅: ASP.NET MVC 2 HiddenField 为空?
Hi,
I am building a ASP.NET MVC 2 website and need to bound the current user/session to some data. The following is possible solutions but what is best practice?
- Create a GUID and set it as hidden field on view, the data will then be saved in a singelton object (like a cache). the security will however not be the best(the user could change the value of the hidden field).
- Use Session.SessionId. to maintain the same SessionId between calls I need to store somthing in the session which feels wrong? Im not sure if there is any security problems here?
BestRegards
My Solution : I ended up to create a GUID for the current client and then set this as a hidden field on the form. I did however had some problems to get the hidden field to be rendered correcly, see : ASP.NET MVC 2 HiddenField is empty?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
跨 Web 请求维护状态始终是一个挑战,因为 Web 本质上是无状态的。
无论您使用隐藏的 Guid(或其他系统唯一标识符)还是 cookie 中的会话 ID,两者都容易被滥用。也就是说,大多数实现“会话状态”的系统都是通过使用 cookie 来实现的。
会话状态“包”的目的是在网络请求之间存储信息,这正是您提到的目标,因此虽然它可能感觉“错误”,但它是一种非常普遍接受的方法。请记住,客户端浏览器仅存储会话 ID,而不是实际的会话数据;这是在服务器上保存的。
Maintaining state across web requests is always a challenge as the web is inherently stateless.
Whether you use a hidden Guid (or other system-unique identifier) or a session ID in a cookie, both are open to abuse. That said, most systems that implement a 'session state' do so through the use of cookies.
The purpose of the session state 'bag' is to store information between web requests, exactly the objective you mention, so while it may feel 'wrong' it is a very commonly accepted approach. Remember, only the session ID is stored with the client browser, not the actual session data; that's held at the server.