【发布时间】:2016-05-12 18:20:00
【问题描述】:
我无法追踪为什么会话在网络应用程序中不断重启。
我已经在Session_End 或Application_End 过程中放置了代码来尝试跟踪正在发生的事情,但是在会话重新启动并再次触发Session_Start 过程之前,代码中都没有到达这两个过程。
有谁知道什么会导致Session_Start 程序在不触发Session_End 或Application_End 程序的情况下重新启动?
基本上,Session_Start 中有代码设置会话变量,Session_End 中有代码尝试记录会话结束的原因
网站上有 100 个或更多的带有 VB 代码的 aspx 页面,看起来会话随机重新启动,有时在加载主页时最多 3 次。我在Session_Start 过程内的 global.asax 页面中设置了一个中断,它在那里中断,所以我可以知道它何时重新加载并丢失在任何 ASPX 页面代码中设置的所有会话变量。
我知道一些常见原因,例如写入某些文件或文件夹(如 App_Data 文件夹)以及应用程序池被回收,但我似乎无法追查为什么会发生这种情况,因为 Session_End 或 Application_End 从未触发并且我无法记录它结束的原因。
我继承了这个“项目”,并在这一点上“探索”了代码,所以感谢你在这方面给我的任何帮助......
服务器是 IIS7,运行 ASP.NET,代码在 VB.NET 中,我还在 web.config 文件中包含了 'sessionState mode="InProc"' 以确保使用会话过程。
这是Session_Start过程中的VB代码
HttpContext.Current.Session.Item("SessionMessageView") = "no"
HttpContext.Current.Session.Item("DefaultMenuName") = "Default"
HttpContext.Current.Session.Item("RootVirtualPath") = "/"
HttpContext.Current.Session.Item("BlockerTested") = False
HttpContext.Current.Session.Item("BlockerTurnedOn") = False
HttpContext.Current.Session.Item("IsMobileBrowser") = False
这是Session_End 和Application_End 过程中的VB 代码
Dim runtime As HttpRuntime = DirectCast(GetType(System.Web.HttpRuntime).InvokeMember("_theRuntime", System.Reflection.BindingFlags.NonPublic Or System.Reflection.BindingFlags.[Static] Or System.Reflection.BindingFlags.GetField, Nothing, Nothing, Nothing), HttpRuntime)
If runtime Is Nothing Then
Return
End If
Dim shutDownMessage As String = DirectCast(runtime.[GetType]().InvokeMember("_shutDownMessage", System.Reflection.BindingFlags.NonPublic Or System.Reflection.BindingFlags.Instance Or System.Reflection.BindingFlags.GetField, Nothing, runtime, Nothing), String)
Dim shutDownStack As String = DirectCast(runtime.[GetType]().InvokeMember("_shutDownStack", System.Reflection.BindingFlags.NonPublic Or System.Reflection.BindingFlags.Instance Or System.Reflection.BindingFlags.GetField, Nothing, runtime, Nothing), String)
If Not System.Diagnostics.EventLog.SourceExists(".NET Runtime") Then
System.Diagnostics.EventLog.CreateEventSource(".NET Runtime", "Application")
End If
Dim log As New System.Diagnostics.EventLog()
log.Source = ".NET Runtime"
log.WriteEntry([String].Format(vbCr & vbLf & vbCr & vbLf & "_shutDownMessage={0}" & vbCr & vbLf & vbCr & vbLf & "_shutDownStack={1}", shutDownMessage, shutDownStack), System.Diagnostics.EventLogEntryType.[Error])
如果我能弄清楚为什么Session_End 过程没有触发而Session_Start 过程多次触发,我可能能够追踪会话重新启动的原因。
【问题讨论】:
-
哪种语言?哪个服务器?一些代码?
-
IIS7,ASP.NET VB,(我确实在 web.config 中有
)我在会话启动过程中设置了许多会话变量,如下所示: -
我这样设置了一个会话变量:Sub Session_Start(ByVal sender As Object, ByVal e As EventArgs) HttpContext.Current.Session.Item("SessionMessageView") = "no" HttpContext.Current .Session.Item("DefaultMenuName") = "Default" HttpContext.Current.Session.Item("RootVirtualPath") = "/" ... End Sub 这是结束会话代码:Sub Session_End(ByVal sender As Object, ByVal e As EventArgs) Dim runtime As HttpRuntime = ... End SUB 希望能给你足够的继续
-
EndSession & End_Application 中的代码获取会话信息并将其写入日志
-
对不起,这是一团糟,编辑问题,不要只是在 cmets 中添加代码。
标签: asp.net session-state