gpt4 book ai didi

c# - 什么使请求成为 asp.net C# 中的新请求

转载 作者:太空宇宙 更新时间:2023-11-03 13:40:38 26 4
gpt4 key购买 nike

好的,基本上我正在尝试在我的 Web 应用程序中实现表单例份验证,为此我需要知道 Web 服务器如何确定请求是否是新请求。这是因为网络服务器为每个新请求创建一个新 session 。

因此,我为每次成功登录创建一个 authenticatecoookie,它是一个持久性 cookie,无论天气如何,用户关闭他/她的浏览器或失去连接,它都会持续到超时,并且必须重新连接,因为此 cookie 存储在客户端计算机上.因此,在这种情况下,假设用户重新连接到服务器并且他的 authenticatecookie 尚未超时。那么他的请求因此已经通过了身份验证,那么这是否也意味着这不是一个新的请求?并且服务器不会为它创建一个新 session ,因为它已经退出了?

另一种情况/场景是,如果 authenticatecookie 在用户重新连接之前超时,请求将不会被验证,但此请求是否也被视为新请求,因此服务器不会为其创建新 session 因为一个人已经退出了吗?

我问这个是因为一旦用户成功登录,我要在 session 中存储什么用户 ID,这样当 authenticatecoookie 超时时,我就可以去检索 session 中的用户 ID 作为 session 时间比 authenticatecookie 晚得多,然后更新我的用户表以指示该用户不再登录

最佳答案

So in that case lets say the user reconnects to the server and his authenticatecoookie hasn't timed-out yet. So his request is therefore already authenticated, so does this also mean that this is not a new request?

从表单例份验证系统的角度来看,这不是新请求,因为该请求提供了有效的表单例份验证 cookie。

and the the server will not create a new session for it as one already exits for it?

session 处理机制不同于表单认证机制。客户端可以使用有效的表单例份验证 cookie 而没有有效的 session cookie 访问服务器(并且,由于这些机制不同,任何组合都是可能的)因此,如果需要 session 而客户端没有 session ,服务器将创建一个新 session 。

so that when the authenticatecoookie times out I can then go and retrive the user-ID in the session as the session times out much later than the authenticatecoookie

如果您的站点主要基于身份验证,也许您应该通过配置比 session 持续时间更长的表单例份验证持续时间来实现。

  • 在您的页面/ Controller /操作上强制执行表单例份验证
  • 在您的页面/操作处理过程中,确保用户 ID 存储在 session 中。如果不是,请存储它以便在 session_end 上可用

关于c# - 什么使请求成为 asp.net C# 中的新请求,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17162724/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com