当应用程序池在ASP.NET MVC中回收时会发生什么? [英] What happens when application pool re-cycles in ASP.NET MVC?

查看:138
本文介绍了当应用程序池在ASP.NET MVC中回收时会发生什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我大量使用Session在服务器上存储来自客户端的已发布请求的数据.在研究中,关于stackoverflow的各种答案都指向我,而不是在ASP.NET MVC中使用Session.主要原因是:在生产服务器的生命周期内,应用程序池经常回收,这也导致会话也回收.

I was using Session heavily for storing data of posted requests from client side on server. On research, various answers over stackoverflow pointing me , Not to use Session in ASP.NET MVC. Main reason is : Application Pool recycles frequently during life time of production server and this causes Session to recycle as well.

那就是为什么我要用反序列化有能力的字符串"...."替换会话对象. 我的全部担心是:包含此字符串(可以反序列化为Object)的单例对象一定不能损坏/回收或在应用程序池回收时重新初始化.

Thatswhy I am thinking to replace session objects with de-serialize able string "....". My whole concern is : This singleton object containing this string (de-serialize able into Objects ) must not corrupt/recycle or re-initialize on app pool re-cycle.

所以我的最后一个问题是:应用程序池回收会发生什么?仅会话循环?还是整个内存重新循环并重新初始化?

So my final question would be : What happens on app pool-recycle? Only Session re-cycles ? Or the whole memory re-cycles and re-initializes?

我的目标Web服务器:带有MVC的Microsoft ASP.NET

My target web server : Microsoft ASP.NET with MVC

推荐答案

应用程序回收时,站点在"w3wp.exe"中运行的Windows进程结束,并创建了一个新进程.一个站点可能为一个应用程序池具有多个工作进程.在这种情况下,它们全部结束并且旋转1,然后将根据需要创建新的工作进程.

When the application recycles, the windows process the site is running in "w3wp.exe" ends and a new one is created. It's also possible a site has multiple worker processes for one application pool. In that case they all end and 1 spins up, and new worker processes will be created as they are needed.

这种情况发生时,网站代码存储在内存中的所有内容都会丢失.这包括进行中的会话信息.

When this happens, anything the website code was storing in memory is lost. This includes In Process Session information.

但是,.Net会话状态可以在两种模式下运行,即进程模式或数据库模式.您可以运行aspnet_regsql工具在sql服务器中创建一个数据库,用于存储会话信息.然后,您可以更改web.config以使会话在数据库中运行.您可以使用相同的会话api,它们在两种模式下均相同.但是,将其置于数据库模式会使它永久保存到数据库中,而不是保留在进程内存中.然后,当AppPool回收时,您什么也不会损失.

However .Net Session State can work in two modes, in process, or database. You can run the aspnet_regsql tool to create a database in sql server for storing session information. Then you can change the web.config to have session run int he database. You can use the same session api's, they work the same in both modes. But putting it in database mode causes it to persist everythign to the database instead of in process memory. Then when AppPool Recycles, you lose nothing.

RegSql文档: https://msdn.microsoft.com/library/ms229862(v = vs.100).aspx

RegSql Doc: https://msdn.microsoft.com/library/ms229862(v=vs.100).aspx

一个经过精心设计的ASP.Net站点(例如MVC,Web窗体,WebApi(1/2))等应被设计为能够从任何回收中完全恢复.网站回收不应破坏您的网站.

A well designed ASP.Net Site (be it MVC, Web Forms, WebApi(1/2)) etc should be designed to be able to fully recover from any recycles. A site recycle should not break your web site.

这篇关于当应用程序池在ASP.NET MVC中回收时会发生什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆