gpt4 book ai didi

c# - 如何在不丢失 session 的情况下更新 asp net webforms 或 mvc 应用程序?

转载 作者:太空狗 更新时间:2023-10-29 21:26:55 25 4
gpt4 key购买 nike

这是我的场景。我在 Windows Server 2012 上的 iis 8 上发布我的 webforms 或 mvc 应用程序。然后我的客户要求其他东西,我必须更新代码隐藏。

例如,表单上的新输入或数据库上的新列。我正在为成员(member)或购物车流程使用 session 变量。

当我在服务器中复制新的 bin 文件时(当我发布我的应用程序时), session 结束。我该如何解决这个更新问题?我该怎么做才能使 session 保持事件状态?因为访问者正在丢失他们的购物车。

感谢您的帮助。

最佳答案

许多事情会导致 IIS 放弃 session :

  • 大量文件更新,ASP.NET 主动为您重新编译。
  • session 自然超时
  • 更新 web.config 会导致它回收
  • 站点应用程序池因其他原因回收

听起来您与第一种行为发生了冲突,而且没有办法阻止这种行为。

听起来您正在使用默认的“处理中” session ,这就是您丢失篮子等的原因。

来自 MSDN :

InProc mode, which stores session state in memory on the Web server. This is the default.

其他选项是:

StateServer mode, which stores session state in a separate process called the ASP.NET state service. This ensures that session state is preserved if the Web application is restarted and also makes session state available to multiple Web servers in a Web farm.

SQLServer mode stores session state in a SQL Server database. This ensures that session state is preserved if the Web application is restarted and also makes session state available to multiple Web servers in a Web farm.

Custom mode, which enables you to specify a custom storage provider.

将 session 切换到其他任何一个都可以让您进行更新,但迁移不是即时的。

关于c# - 如何在不丢失 session 的情况下更新 asp net webforms 或 mvc 应用程序?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34923883/

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