简体   繁体   English

当应用程序池在 ASP.NET MVC 中回收时会发生什么?

[英]What happens when application pool re-cycles in ASP.NET MVC?

I was using Session heavily for storing data of posted requests from client side on server.我大量使用 Session 来存储来自客户端的已发布请求的数据在服务器上。 On research, various answers over stackoverflow pointing me , Not to use Session in ASP.NET MVC.在研究中,stackoverflow 上的各种答案都指向我,不要在 ASP.NET MVC 中使用 Session。 Main reason is : Application Pool recycles frequently during life time of production server and this causes Session to recycle as well.主要原因是:应用程序池在生产服务器的生命周期内频繁回收,这也会导致会话回收。

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.我的全部担忧是:包含此字符串的单例对象(可反序列化为 Objects )不得在应用程序池回收时损坏/回收或重新初始化。

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?或者整个内存重新循环并重新初始化?

My target web server : Microsoft ASP.NET with MVC我的目标网络服务器:Microsoft ASP.NET with MVC

When the application recycles, the windows process the site is running in w3wp.exe ends and a new one is created.当应用程序回收时,该站点在w3wp.exe运行的 Windows 进程结束并创建一个新进程。 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.在这种情况下,它们都结束并且 1 旋转,并且将根据需要创建新的工作进程。

When this happens, anything the website code was storing in memory is lost.发生这种情况时,网站代码存储在内存中的任何内容都会丢失。 This includes In Process Session information.这包括正在进行的会话信息。

However .Net Session State can work in two modes, in process, or database.但是 .Net 会话状态可以在两种模式下工作,进程中或数据库中。 You can run the aspnet_regsql tool to create a database in sql server for storing session information.可以运行aspnet_regsql工具在sql server中创建一个数据库来存储会话信息。 Then you can change the web.config to have session run in the database.然后您可以更改 web.config 以在数据库中运行会话。 You can use the same session apis, they work the same in both modes.您可以使用相同的会话 API,它们在两种模式下的工作方式相同。 But putting it in database mode causes it to persist everything to the database instead of in process memory.但是将其置于数据库模式会导致它将所有内容持久化到数据库中,而不是在进程内存中。 Then when AppPool recycles, you lose nothing.然后当 AppPool 回收时,你不会失去任何东西。

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

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.一个设计良好的 ASP.Net 站点(无论是 MVC、Web Forms、WebApi(1/2))等都应该被设计成能够从任何回收中完全恢复。 A site recycle should not break your web site.网站回收不应破坏您的网站。

Recycling the Application Pool will blow away your AppDomain and everything in it, including all static values.回收应用程序池将吹走您的 AppDomain 及其中的所有内容,包括所有静态值。

This is why it loses session state in the first place.这就是它首先丢失会话状态的原因。

You probably want a database.你可能想要一个数据库。

SLaks pretty much answered your question. SLaks 几乎回答了你的问题。 Here is the solution -这是解决方案 -

In ASP.Net MVC, we do not use Session State like Web Form.在 ASP.Net MVC 中,我们不像 Web Form 那样使用会话状态。

However, you can still use Session State, but you want to use external Session State provider instead of default InProc mode - values and variables are stored in memory on the local Web server.但是,您仍然可以使用会话状态,但您希望使用外部会话状态提供程序而不是默认的InProc 模式- 值和变量存储在本地 Web 服务器的内存中。

You have few options -你有几个选择——

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

相关问题 向文件夹应用程序池授予访问权限(ASP.NET MVC) - Grant acess to folder application pool (ASP.NET MVC) 当用户在收到响应之前导航时,ASP.NET MVC控制器会发生什么? - What happens to an ASP.NET MVC controller when the user navigates away before a response is received? ASP.NET MVC验证和模型属性,首先发生什么? - ASP.NET MVC Validation and Model Properties, what happens first? 当用户在 FTP 发布期间访问 ASP.NET MVC 网站时会发生什么? - What happens when a user accesses to an ASP.NET MVC website during FTP publishing? 在IISIntegration上运行ASP.NET Core应用程序时,Program.Main会发生什么情况? - What happens of Program.Main when an ASP.NET Core application is run on IISIntegration? IIS 6.0上的asp.net Web应用程序(asmx ws)空闲数小时左右会发生什么? - what happens to asp.net web application (asmx ws) on IIS 6.0 when it's idle for hours or so? 与MySQL和ASP.NET MVC合并 - Pool with MySQL and ASP.NET MVC ASP.Net 应用程序池内存泄漏 - ASP.Net Application pool memory leak 在开发多租户asp.net MVC应用程序时要记住什么? - What to keep in mind when developing a multi-tenant asp.net MVC application? 登录ASP.Net MVC应用程序需要什么请求信息 - What request info to log in an ASP.Net MVC application
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM