I am running a MVC4 asp.net app and it deals with create/delete folder inside the app folder.
我正在运行一个MVC4 asp.net应用程序,它处理应用程序文件夹中的创建/删除文件夹。
The session stay when the app create or delete folders.
当应用程序创建或删除文件夹时,会话将保持不变。
But the session was lost when the app create a folder then delete one after another.
但是当应用程序创建一个文件夹然后一个接着一个地删除时,会话就丢失了。
I have place this snippet in Global.asax as a resolve to maintain the session even there are changes in the physical folder inside the app:
我将这段代码放在全局栏中。asax用于维护会话,即使应用程序内部的物理文件夹发生了更改:
PropertyInfo p = typeof(System.Web.HttpRuntime).GetProperty("FileChangesMonitor", indingFlags.NonPublic | BindingFlags.Public | BindingFlags.Static);
object o = p.GetValue(null, null);
FieldInfo f = o.GetType().GetField("_dirMonSubdirs", BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.IgnoreCase);
object monitor = f.GetValue(o);
MethodInfo m = monitor.GetType().GetMethod("StopMonitoring", BindingFlags.Instance | BindingFlags.NonPublic);
m.Invoke(monitor, new object[] { });
Is there any way to fix this without moving the folder location outside the app folder?
有没有办法在不将文件夹位置移到app文件夹之外的情况下修复这个问题?
2 个解决方案
#1
1
Maybe you could put your session in the database, and that would keep it alive.
也许你可以把你的会话放在数据库中,这样就能让它保持活跃。
"Configure SQL Server for ASP.NET SQL Server Session State" http://support.microsoft.com/kb/317604
为ASP配置SQL Server。NET SQL Server会话状态" http://support.microsoft.com/kb/317604
Edit: For Windows Azure, I would go for Windows Azure Cache. Refer to: http://msdn.microsoft.com/en-us/library/windowsazure/gg185668.aspx and https://www.simple-talk.com/cloud/platform-as-a-service/managing-session-state-in-windows-azure-what-are-the-options/ I believe that would not be affected by recycling the application.
编辑:对于Windows Azure,我选择Windows Azure Cache。参考:http://msdn.microsoft.com/en-us/library/windowsazure/gg185668.aspx和https://www.simple-web-k.com/cloud/platform as-a-service/managing-session-state in-windows- az-what -are- options/我认为这不会受到应用程序回收的影响。
Or for a more generic solution, this using Microsoft ASP.NET Universal Providers might work: http://www.nuget.org/packages/Microsoft.AspNet.Providers
或者更通用的解决方案,使用Microsoft ASP。NET Universal provider可以工作:http://www.nuget.org/packages/microsoft.aspnet.provider
#2
1
If you modify anything inside the bin subfolder, the application will be recycled, which will cause an InProc session to be lost.
如果您修改bin子文件夹中的任何内容,应用程序将被回收,这将导致InProc会话丢失。
I wouldn't expect the application to be recycled if you create/delete folders other than bin, but you can easily check this by adding a trace statement to Application_End. If this event is fired, your application is being recycled.
如果您创建/删除除bin之外的文件夹,我不希望应用程序被回收,但是您可以通过向Application_End添加跟踪语句来轻松地检查这一点。如果这个事件被触发,您的应用程序将被回收。
Application recycling following a modification to the bin directory is by design, and I wouldn't attempt to interfere with it by reflecting on private ASP.NET methods.
对bin目录进行修改后的应用程序回收是经过设计的,我不会试图通过在私有ASP上进行反射来干扰它。净的方法。
You could try using an out-proc SessionState mode (StateServer or SQLServer)
您可以尝试使用out-proc SessionState模式(StateServer或SQLServer)
#1
1
Maybe you could put your session in the database, and that would keep it alive.
也许你可以把你的会话放在数据库中,这样就能让它保持活跃。
"Configure SQL Server for ASP.NET SQL Server Session State" http://support.microsoft.com/kb/317604
为ASP配置SQL Server。NET SQL Server会话状态" http://support.microsoft.com/kb/317604
Edit: For Windows Azure, I would go for Windows Azure Cache. Refer to: http://msdn.microsoft.com/en-us/library/windowsazure/gg185668.aspx and https://www.simple-talk.com/cloud/platform-as-a-service/managing-session-state-in-windows-azure-what-are-the-options/ I believe that would not be affected by recycling the application.
编辑:对于Windows Azure,我选择Windows Azure Cache。参考:http://msdn.microsoft.com/en-us/library/windowsazure/gg185668.aspx和https://www.simple-web-k.com/cloud/platform as-a-service/managing-session-state in-windows- az-what -are- options/我认为这不会受到应用程序回收的影响。
Or for a more generic solution, this using Microsoft ASP.NET Universal Providers might work: http://www.nuget.org/packages/Microsoft.AspNet.Providers
或者更通用的解决方案,使用Microsoft ASP。NET Universal provider可以工作:http://www.nuget.org/packages/microsoft.aspnet.provider
#2
1
If you modify anything inside the bin subfolder, the application will be recycled, which will cause an InProc session to be lost.
如果您修改bin子文件夹中的任何内容,应用程序将被回收,这将导致InProc会话丢失。
I wouldn't expect the application to be recycled if you create/delete folders other than bin, but you can easily check this by adding a trace statement to Application_End. If this event is fired, your application is being recycled.
如果您创建/删除除bin之外的文件夹,我不希望应用程序被回收,但是您可以通过向Application_End添加跟踪语句来轻松地检查这一点。如果这个事件被触发,您的应用程序将被回收。
Application recycling following a modification to the bin directory is by design, and I wouldn't attempt to interfere with it by reflecting on private ASP.NET methods.
对bin目录进行修改后的应用程序回收是经过设计的,我不会试图通过在私有ASP上进行反射来干扰它。净的方法。
You could try using an out-proc SessionState mode (StateServer or SQLServer)
您可以尝试使用out-proc SessionState模式(StateServer或SQLServer)