且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

asp.net中的会话冲突

更新时间:2023-09-11 23:24:40

我已经看到从生产服务器使用Web园艺的测试到生产的这种行为(多个工作进程) ).对我来说,我在某些代码中发现了一个问题,其中开发人员使用静态变量来管理状态.使用网络园艺,您不能使用静态,因为您的下一个请求可能无法获得相同的过程.这意味着如果IIS分配了另一个工作进程,则下次发送请求时,所有静态变量分配都将丢失,或者您将选择其他用户.

我的建议是检查您的应用程序池配置,将辅助进程的数量设置为1,然后查看您是否仍然具有相同的行为.

如果该行为消失,则说明您未正确处理状态.尽管取决于您的编码方式,但您可能会看到两个用户都选择了最后一个登录者的状态.这两种方式都突出显示了状态管理问题.

如果行为仍然存在,请通知我,我会再考虑.
I''ve seen behaviour like this when moving from test to production where the production server was using web gardening (Multiple worker processes). For me I found an issue in some code where the developer was using static variables for managing state. With web gardening you can''t use statics as you may not get the same process for your next request. Which means the next time you send a request if IIS assigns a different worker process, any static variable assignments will be lost, or you''ll pick up another users.

My advice would be check your application pool configuration, set the number of worker processes to 1 and see if you still get the same behaviour.

If the behaviour disappears then you''re not handling state correctly. Although depending on how you''ve coded it you may see that both users pick up the state of the last person to log in. Either way it highlights a state management issue.

If the behaviour is still there then let me know and I''ll think again.