locked
session is being terminated after a page loads RRS feed

  • Question

  • User575815776 posted
    My session ends after loading my web form. This is unintended. Does anyone have a clue why my ASP.NET application would behave in this way? I put debug code in my Session_End and Application_End events in the Global.asax. Sure enough, I discovered that the system terminates my session following the conclusion of loading a web form -- for all web forms I have constructed thus far. Here are my Web.Config sessionState settings: <sessionState mode="InProc" stateConnectionString="tcpip=127.0.0.1:42424" sqlConnectionString="data source=127.0.0.1;user id=sa;password=" cookieless="false" timeout="20" />Your help greatly appreciated, -Geoffrey
    Wednesday, July 16, 2003 1:45 PM

All replies

  • User777594459 posted
    Did your app got restarted? Maybe this faq can help you: http://www.asp.net/Forums/ShowPost.aspx?tabindex=1&PostID=7504
    Wednesday, July 16, 2003 9:00 PM
  • User575815776 posted
    I am in the Visual Studio IDE, running my application in debug mode, and this happens. How do I know if the application is being restarted? Why would it restart consistently following the loading of each and every page? If it was restarting, wouldn't it end my debug session? Confused, -Geoffrey
    Thursday, July 17, 2003 5:25 PM
  • User777594459 posted
    First, I don't think appdomain restart will end your debug session. Second, appdomain restart is one possibility. Does your problem exist outside out VS IDE? You can use perfmon counters to check if appdomain restart has ever happened. There is another faq you may find helpful: http://www.asp.net/Forums/ShowPost.aspx?tabindex=1&PostID=232621 Another possible explanation is that somehow your code is calling session.abandon(). But I assume that's not the case.
    Friday, July 18, 2003 1:40 PM
  • User2048951784 posted
    Yos raised this a while back, did you ever find out why its happening. Because I'm getting almost the same thing and its doing my head in.... Problem developing a .NET Web application. Session variables lost one first execution after build. Steps: 1) I create a new project on MY ( localHost ) machine. 2) I have 2 pages webform1.aspx and webform2.aspx. 3) I create a session variable in webform1.aspx 4) In webform2.aspx I try to just response.write the session variable created in webform1.aspx 5) Build the code. 6) Run the page webform1.aspx (OK) 7) Change the URL to webform2.aspx ( Session variable written out OK) Everything works OK. I copy the project over to our server (drag and drop all files) The first time I run it, loads first page webform1.aspx I then change the url to webform2.aspx Problem: This time the session variable is NOT written out. If I shutdown the browser and try running it again. It works fine. The session is maintained across to the 2nd page. Testing: 1) Anytime I change the webconfig, global.asax or code behind pages, I expect the code to re-compile. But I don't see why I need to run the application twice before sessions are maintained across pages. 2) I ran it in debug mode and I found that on the first run: At the end of the first page loading, Both Session_End and Application_End were firing. Other Information: Developed with Visual Studio version 7.1.3088 IIS Version 5.0 Server has Visual Studio Pre-requisites IIS Version 5.0
    Thursday, September 16, 2004 8:19 AM
  • User1413581374 posted

     Hi,

    I am getting a similar issue.

    I found that my sessions were being ended abruptly. I found that if there was any errors (such as object not set to...) then session would end. I made sure no more errors as such would occur but the session is still be ended. There is no application error occuring and I'm setting the timeout to be 10 minutes.

    I did see in the locals output the following issue though don't know how to handle it?

    '((ASP.global_asax)(this)).Profile' threw an exception of type 'System.NullReferenceException'

    However, In my code I step through every line and there is no null reference issues anymore... I cleaned and rebuilt the project many times and stepped through many times but yet can't see why the session is ending.

    I went into IIS properties and made sure that the settings were not to close the sessions for 20 minutes.

    If anyone has any answers or suggestions I'd be very happy to hear them.

    Cheers,

    Daniel

    Monday, August 24, 2009 11:43 PM
  • User2115139740 posted

    check out this link for session problem, in addition i suggest u to add code in global.asax to make sure what is the reason for session end


    Session Timeouts Causes and Remedies
    http://www.c-sharpcorner.com/UploadFile/technoNet/SessionTimeout02192009052301AM/SessionTimeout.aspx 

    Below is the code for adding into Global.asax, this will give an output is session ends 


     Sub Application_End(ByVal sender As Object, ByVal e As EventArgs)
            ' Code that runs on application shutdown
            Try
                Dim runtime As HttpRuntime = DirectCast(GetType(System.Web.HttpRuntime).InvokeMember("_theRuntime", Reflection.BindingFlags.NonPublic Or Reflection.BindingFlags.[Static] Or Reflection.BindingFlags.GetField, Nothing, Nothing, Nothing), HttpRuntime)
                If runtime Is Nothing Then
                    Return
                End If
                Dim shutDownMessage As String = DirectCast(runtime.[GetType]().InvokeMember("_shutDownMessage", Reflection.BindingFlags.NonPublic Or Reflection.BindingFlags.Instance Or Reflection.BindingFlags.GetField, Nothing, runtime, Nothing), String)
                Dim shutDownStack As String = DirectCast(runtime.[GetType]().InvokeMember("_shutDownStack", Reflection.BindingFlags.NonPublic Or Reflection.BindingFlags.Instance Or Reflection.BindingFlags.GetField, Nothing, runtime, Nothing), String)
                'Dim objErr As Exception = Server.GetLastError().GetBaseException()
           
                oErrHandle.WriteErrorLog(1, "Global.asax", "Application_End", shutDownMessage, "Error", "admin")
            Catch ex As Exception
                oErrHandle.WriteErrorLog(1, "Global.asax", "Application_End", ex.Message, ex.GetBaseException.StackTrace.ToString.Trim, "admin")
            End Try
        End Sub
            
        Sub Application_Error(ByVal sender As Object, ByVal e As EventArgs)
            ' Code that runs when an unhandled error occurs
            Try
                
                Dim objErr As Exception = Server.GetLastError().GetBaseException()
                
                oErrHandle.WriteErrorLog(1, IO.Path.GetFileName(Me.Request.PhysicalPath), "Application_Error", objErr.Message.ToString(), objErr.GetBaseException.StackTrace.ToString.Trim, "admin")
            Catch ex As Exception
                oErrHandle.WriteErrorLog(1, "Global.asax", "Application_Error", ex.Message, ex.GetBaseException.StackTrace.ToString.Trim, "admin")
            End Try
        End Sub

     Sub Application_End(ByVal sender As Object, ByVal e As EventArgs)
    
            ' Code that runs on application shutdown
    
            Try
    
                Dim runtime As HttpRuntime = DirectCast(GetType(System.Web.HttpRuntime).InvokeMember("_theRuntime", Reflection.BindingFlags.NonPublic Or Reflection.BindingFlags.[Static] Or Reflection.BindingFlags.GetField, Nothing, Nothing, Nothing), HttpRuntime)
    
                If runtime Is Nothing Then
    
                    Return
    
                End If
    
                Dim shutDownMessage As String = DirectCast(runtime.[GetType]().InvokeMember("_shutDownMessage", Reflection.BindingFlags.NonPublic Or Reflection.BindingFlags.Instance Or Reflection.BindingFlags.GetField, Nothing, runtime, Nothing), String)
    
    
    
                Dim shutDownStack As String = DirectCast(runtime.[GetType]().InvokeMember("_shutDownStack", Reflection.BindingFlags.NonPublic Or Reflection.BindingFlags.Instance Or Reflection.BindingFlags.GetField, Nothing, runtime, Nothing), String)
    
    
    
                'Dim objErr As Exception = Server.GetLastError().GetBaseException()
    
           
    
                oErrHandle.WriteErrorLog(1, "Global.asax", "Application_End", shutDownMessage, "Error", "admin")
    
            Catch ex As Exception
    
                oErrHandle.WriteErrorLog(1, "Global.asax", "Application_End", ex.Message, ex.GetBaseException.StackTrace.ToString.Trim, "admin")
    
            End Try
    
        End Sub
    
            
    
        Sub Application_Error(ByVal sender As Object, ByVal e As EventArgs)
    
            ' Code that runs when an unhandled error occurs
    
            Try
    
                
    
                Dim objErr As Exception = Server.GetLastError().GetBaseException()
    
                
    
                oErrHandle.WriteErrorLog(1, IO.Path.GetFileName(Me.Request.PhysicalPath), "Application_Error", objErr.Message.ToString(), objErr.GetBaseException.StackTrace.ToString.Trim, "admin")
    
            Catch ex As Exception
    
                oErrHandle.WriteErrorLog(1, "Global.asax", "Application_Error", ex.Message, ex.GetBaseException.StackTrace.ToString.Trim, "admin")
    
            End Try
    
        End Sub




    OutPut will be like this way :-

    09:29:37.7894980

    Serverity     :1

    ClassName     :Global.asax

    Method Name   :Application_End

    Error Text    :CONFIG change

    HostingEnvironment initiated shutdown

    CONFIG change

    CONFIG change

    HostingEnvironment caused shutdown

    Error Desc.    :Error


    -----------------------------------------------------

    10:30:00.3320242

    Serverity     :1

    ClassName     :Global.asax

    Method Name   :Application_End

    Error Text    :Change Notification for critical directories.

    bin dir change or directory rename

    HostingEnvironment initiated shutdown

    Change Notification for critical directories.

    bin dir change or directory rename

    Change Notification for critical directories.

    bin dir change or directory rename

    Change Notification for critical directories.

    bin dir change or directory rename

    Change Notification for critical directories.

    bin dir change or directory rename

    Change Notification for critical directories.

    bin dir change or directory rename

    Change Notification for critical directories.

    bin dir change or directory rename

    Change Notification for critical directories.

    bin dir change or directory rename

    Change Notification for critical directories.

    bin dir change or directory rename

    HostingEnvironment caused shutdown

    Error Desc.    :Error


    17:12:24.1534037

    Serverity     :1

    ClassName     :Global.asax

    Method Name   :Application_End

    Error Text    :Recompilation limit of 15 reached

    HostingEnvironment initiated shutdown

    HostingEnvironment caused shutdown

    Error Desc.    :Error


    and other error(s) it will show up



    Monday, August 24, 2009 11:54 PM
  • User1413581374 posted

    Hi Manoj0682,

    Firstly, thanks for your speedy response :)

    What would be causing directory rename or changes? I am doing logging to the bin directory. Should I not be doing this?

    I got the following output:

    Change Notification for critical directories.

    bin dir change or directory rename
    HostingEnvironment initiated shutdown
    Change Notification for critical directories.
    bin dir change or directory rename
    Change Notification for critical directories.
    bin dir change or directory rename
    Change Notification for critical directories.
    bin dir change or directory rename
    Change Notification for critical directories.
    bin dir change or directory rename
    Change Notification for critical directories.
    bin dir change or directory rename
    HostingEnvironment caused shutdown
    Change in C:\\Windows\\Microsoft.NET\\Framework\\v2.0.50727\\Temporary ASP.NET Files\\root\\244e30b9\\60f41a09\\hash\\hash.web"

    "   at System.Environment.GetStackTrace(Exception e, Boolean needFileInfo)
       at System.Environment.get_StackTrace()  
    at System.Web.Hosting.HostingEnvironment.InitiateShutdownInternal()  
    at System.Web.Hosting.HostingEnvironment.InitiateShutdown()  
    at System.Web.HttpRuntime.ShutdownAppDomain(String stackTrace)  
    at System.Web.HttpRuntime.OnCriticalDirectoryChange(Object sender, FileChangeEvent e)  
    at System.Web.FileChangesMonitor.OnCriticaldirChange(Object sender, FileChangeEvent e)  
    at System.Web.DirectoryMonitor.FireNotifications()
       at System.Web.Util.WorkItem.CallCallbackWithAssert(WorkItemCallback callback)  
    at System.Web.Util.WorkItem.OnQueueUserWorkItemCompletion(Object state)  
    at System.Threading._ThreadPoolWaitCallback.WaitCallback_Context(Object state)  
    at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)  
    at System.Threading._ThreadPoolWaitCallback.PerformWaitCallbackInternal(_ThreadPoolWaitCallback tpWaitCallBack)
    at System.Threading._ThreadPoolWaitCallback.PerformWaitCallback(Object state)"

    Tuesday, August 25, 2009 12:35 AM
  • User2115139740 posted

    Whenever U change to *.dll files or App_Code folder files changes then you will get above error. 

    hope this info will help you :)

    Tuesday, August 25, 2009 12:43 AM
  • User1413581374 posted

    Thanks Manoj0682 :)

    I couldn't find the "Accepted Answer" button , maybe because I wasn't the original author of the thread.

    Cheers,

    Dan 

    Tuesday, August 25, 2009 1:06 AM
  • User2115139740 posted

    May be original author can do.

    However, my main intention to share my knowledge to other people. I am happy that you got your answer. 

    Tuesday, August 25, 2009 1:10 AM
  • User-595680635 posted

    I'm facing the same problem. When the page loads, session_end event in global.asax gets fired. Page works fine except it throws an exception. I don't this just because of an exception, the session_end would get fired. Any Ideas. Need help seriously.

    Thursday, May 5, 2011 5:54 AM
  • User-25350103 posted

    hi,

    I am also facing same issue and struggling for solution.i  have an asp.net site .net 4.0 after login when a usercontrol is getting loaded suddenly Session_end event gets called and user rediarected to login page.Please help

    Akanksha

    Friday, April 26, 2013 5:18 AM
  • User1502990794 posted

    Have you declared your session variable in global.asax file? 

    Saturday, April 27, 2013 1:45 AM
  • User-25350103 posted

    hi,

    I am getting following call stack when session ends abruptly:-

    2013-04-30 10:51:44 [I][1]  : Session_End
    2013-04-30 10:51:44 [I][1]  : _InvokeMethodFast
    2013-04-30 10:51:44 [I][1]  : InvokeMethodFast
    2013-04-30 10:51:44 [I][1]  : Invoke
    2013-04-30 10:51:44 [I][1]  : Invoke
    2013-04-30 10:51:44 [I][1]  : Invoke
    2013-04-30 10:51:44 [I][1]  : InvokeMethodWithAssert
    2013-04-30 10:51:44 [I][1]  : ProcessSpecialRequest
    2013-04-30 10:51:44 [I][1]  : FireSessionOnEnd
    2013-04-30 10:51:44 [I][1]  : RaiseOnEndCallback
    2013-04-30 10:51:44 [I][1]  : CallCallbackWithAssert
    2013-04-30 10:51:44 [I][1]  : OnQueueUserWorkItemCompletion
    2013-04-30 10:51:44 [I][1]  : WaitCallback_Context
    2013-04-30 10:51:44 [I][1]  : runTryCode
    2013-04-30 10:51:44 [I][1]  : ExecuteCodeWithGuaranteedCleanup
    2013-04-30 10:51:44 [I][1]  : RunInternal
    2013-04-30 10:51:44 [I][1]  : Run
    2013-04-30 10:51:44 [I][1]  : System.Threading.IThreadPoolWorkItem.ExecuteWorkItem
    2013-04-30 10:51:44 [I][1]  : Dispatch
    2013-04-30 10:51:44 [I][1]  : PerformWaitCallback

    not able to identify what causing this call stack.can any one help?

    Tuesday, April 30, 2013 1:28 AM