在asp.net中丢失会话

时间:2017-04-24 09:25:45

标签: asp.net multithreading recycle

嗨,抱歉我的英语不好,

我有一个Asp.Net应用程序工作正常,直到我添加Log.Net框架(登录单个文件)并在线程中添加图片生成。

随机丢失所有会话变量。

我尝试不使用Log4Net登录(在配置文件中)。

我在global.asax中添加了登录session_end以了解为什么应用程序池回收已经启动并且我得到了这个堆栈跟踪:

shutDownMessage=CONFIG change
HostingEnvironment initiated shutdown
HostingEnvironment a provoqué un arrêt.

_shutDownStack=   à System.Environment.GetStackTrace(Exception e, Boolean needFileInfo)
   à System.Environment.get_StackTrace()
   à System.Web.Hosting.HostingEnvironment.InitiateShutdownInternal()
   à System.Web.Hosting.HostingEnvironment.InitiateShutdownWithoutDemand()
   à System.Web.HttpRuntime.ShutdownAppDomain(String stackTrace)
   à System.Web.Configuration.HttpConfigurationSystem.OnConfigurationChanged(Object sender, InternalConfigEventArgs e)
   à System.Configuration.Internal.InternalConfigRoot.OnConfigChanged(InternalConfigEventArgs e)
   à System.Configuration.BaseConfigurationRecord.OnStreamChanged(String streamname)
   à System.Web.Configuration.WebConfigurationHostFileChange.OnFileChanged(Object sender, FileChangeEvent e)
   à System.Web.DirectoryMonitor.FireNotifications()
   à System.Web.Util.WorkItem.CallCallbackWithAssert(WorkItemCallback callback)
   à System.Web.Util.WorkItem.OnQueueUserWorkItemCompletion(Object state)
   à System.Threading.QueueUserWorkItemCallback.WaitCallback_Context(Object state)
   à System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
   à System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
   à System.Threading.QueueUserWorkItemCallback.System.Threading.IThreadPoolWorkItem.ExecuteWorkItem()
   à System.Threading.ThreadPoolWorkQueue.Dispatch()
   à System.Threading._ThreadPoolWaitCallback.PerformWaitCallback()

ShutDownMessage是“CONFIG change”但我在配置文件中没有任何变化,即使在bin文件夹中也是如此。

我唯一做的就是在网站的特定文件夹中删除和创建图片。

Asp.Net文件更改通知是否导致即使我在bin文件夹中没有更改也会启动App Recycling?

提前感谢您的帮助。

2 个答案:

答案 0 :(得分:0)

如果它可以帮助某人:

添加FCNMode注册码帮助我

https://weblogs.asp.net/owscott/ASP.NET-v2.0-2D00-AppDomain-recycles_2C00_-more-common-than-before

“此外,如果相互之间短时间连续添加了十几个文件,那么同样重新启动” - >网站文件夹中的线程中的图片生成导致AppDomain为我回收(使用Windows Server 2012 R2)。

答案 1 :(得分:0)

global.asax中的这段代码也有效:

  Dim theRuntime = GetType(HttpRuntime).GetField("_theRuntime", BindingFlags.NonPublic Or BindingFlags.[Static]).GetValue(Nothing)
    Dim fcmField = GetType(HttpRuntime).GetField("_fcm", BindingFlags.NonPublic Or BindingFlags.Instance)
    Dim fcm = fcmField.GetValue(theRuntime)

    fcmField.FieldType.GetMethod("Stop", BindingFlags.Instance Or BindingFlags.NonPublic).Invoke(fcm, Nothing)