c# - ASP.NET MVC session 状态超时

标签 c# asp.net asp.net-mvc session session-state

假设 session 状态为not reccomended在 ASP.NET MVC 中。我试图了解在什么情况下使用 session 。我知道使用 TempData 会创建一个 session ,但是还有哪些其他情况,以及如何配置 session 状态超时以获得更好的安全性是否重要?

<sessionState cookieName="s" timeout="20" />

最佳答案

您引用的已接受答案已部分说明

This tended to lead to an overuse of session, populating "current" variables in session intended to indicate what the current object being interacted with was. This overuse in turn made applications very state-dependent and much harder to determine expected behaviour ("Is this variable populated?" "Do I have the current order ID yet?").

MVC is structured around the idea that your website is a view into a logical model of information. It encourages having stateless operations through the use of simple controllers responding to actions with key information passed as part of the HTTP request

当您的网站需要将某些内容与特定用户绑定(bind)时,无论是出于安全还是个性化目的, session 并不是一件坏事。为此目的使用 session 是正常的、预期的和正常的。

您应该避免在 session 中填充 Web 应用程序中任何位置可能需要的所有信息。花时间学习和理解 MVC 架构,并支持在实际呈现给定页面时加载呈现该页面所需的数据。仅缓存加载成本相对较高或许多/所有页面都需要的内容。

does it matter how I configure the session state timeout for better security?

session 超时的主要问题是 session 劫持攻击,它允许中间人拦截 session 信息并在黑客的控制下从不同设备控制 session 。对于大多数应用程序,我没有发现默认 session 超时有任何问题。

另一个令人担忧的问题是人们离开他们的设备,使其无人看管。这样做的人比仅仅对您的网站有更大的安全担忧。

关于c# - ASP.NET MVC session 状态超时,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29972948/

相关文章:

C# ASP.NET AJAX CascadingDropDown 选定值属性问题

asp.net-mvc - 如何在 mvc 的 apicontroller 中获取部分 View 字符串

c# - 结合两个 LINQ 查询的优雅方式

javascript - 如何从使用代码隐藏和 c# 创建的 javascript 调用 session

asp.net - 格式验证摘要

c# - 1对1关系EF两个外键报错

c# - 发现多个类型与名为 'Home' 的 Controller 匹配 - 在两个不同的区域

c# - 在没有引用的情况下记录整个类库

c# - 绑定(bind)到第二个属性

javascript - 单击特定按钮时的确认框