简体   繁体   English

重建后,ASP.NET / IIS中的会话为空

[英]Session empty in ASP.NET / IIS after rebuild

I'm working on an ASP.NET MVC web application and I've made my own authentication module, which is session-based (no cookies). 我正在开发一个ASP.NET MVC Web应用程序,我已经创建了自己的身份验证模块,这是基于会话的(没有cookie)。 The problem is: When I rebuild my application, I'm automatically logged of (session is empty). 问题是:当我重建我的应用程序时,我会自动记录(会话为空)。

Normally this is not a big problem because my application is not 'automatically' rebuilding in a production environment. 通常这不是一个大问题,因为我的应用程序不是在生产环境中“自动”重建。 But I've also made a module that changes the resource-files and after a modification of a resource file, the application seems to rebuild automatically. 但我还创建了一个更改资源文件的模块,在修改资源文件后,应用程序似乎会自动重建。

So my actual question: Is it possible to 'keep' the session variables/stay logged on after a rebuild? 所以我的实际问题是:是否有可能“保持”会话变量/在重建后保持登录状态?

You'll need to use something other than InProc sessions. 您需要使用InProc会话之外的其他内容。 You'll need to look at using either ASP.net State Server, or a SQL server as the backing store for your sessions. 您需要查看使用ASP.net State Server或SQL Server作为会话的后备存储。 These can be a bit slower, but are more resilient. 这些可能会慢一点,但更有弹性。

As Paddy notes, you will need to use something other than InProc sessions. 正如Paddy所说,你需要使用InProc会话以外的东西。 Go to MSDN to see how to change to either a SQL or Windows Service based solution. 转到MSDN以查看如何更改为基于SQL或Windows服务的解决方案。

Actually I think it is good practice to always use out-of-proc sessions. 实际上我认为总是使用进程外会话是一种好习惯。 The performance hit when using the ASP.NET State Service on the same box is minimal and you won't experience any nasty surprises if you decide to change the Session State mechanism at some point in the future (while running InProc you can shove anything in the Session, but once you use out-of-proc session state, the data has to be serializable, which may come as a nasty surprise at a time when surprises are not welcome). 在同一个盒子上使用ASP.NET状态服务时的性能损失很小,如果您决定在将来某个时候更改会话状态机制,您将不会遇到任何令人讨厌的意外(在运行InProc时,您可以推送任何内容会话,但是一旦你使用了进程外会话状态,数据必须是可序列化的,这可能会在不受欢迎的时候出现令人讨厌的惊喜。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM