Re: session variable getting lost



George, thanks for you suggestion. I have implemented the Application_End
routine in Global.aspx and the application is getting shut down with the
following information. If you can help it would be great:

HostingEnvironment caused shutdown

at System.Environment.GetStackTrace(Exception e, Boolean needFileInfo)
at System.Environment.get_StackTrace()
at System.Web.HttpRuntime.ShutdownAppDomain()
at System.Web.Hosting.HostingEnvironment.ShutdownThisAppDomainOnce()
at
System.Web.Hosting.HostingEnvironment.InitiateShutdownWorkItemCallback(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.PerformWaitCallback(Object
state)


S

"George Ter-Saakov" <gt-nsp@xxxxxxxxxxx> wrote in message
news:eafVuXYIIHA.5352@xxxxxxxxxxxxxxxxxxxxxxx
Here are some guesses why session might be lost.

1. Host must be the same. Example http://www.mysite.com and
http://mysite.com might be 2 different sites. Thus browser does not pass
cookies from one to another. Thus session might be lost. If for example
you logged in into http://mysite.com/login.aspx and then got redirected to
http://www.mysite.com

2. Basically comes from #1. http://www.mysite.com and
http://132.234.123.123 are 2 different sites even if www.mysite.com
resolves to 132.234.123.123

3. Application is recycled.
To verify #3 add folowing code to Global.asax You need to replace last
line clsGlobal.SendEmail with your emailing code.
This will send an email to you with a reason everytime application was
shutdown. Thus you will know.....Unless of course someone pulls a power
plug from the server. Then no email will be sent :)

protected void Application_End(Object sender, EventArgs e)

{

HttpRuntime runtime =
(HttpRuntime)typeof(System.Web.HttpRuntime).InvokeMember("_theRuntime",

BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.GetField,
null, null, null);

if (runtime == null)

return;

string shutDownMessage =
(string)runtime.GetType().InvokeMember("_shutDownMessage",

BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.GetField,
null, runtime, null);

string shutDownStack =
(string)runtime.GetType().InvokeMember("_shutDownStack",

BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.GetField,
null, runtime, null);

//send email to me

clsGlobal.SendEmail(String.Format("\r\n\r\n_shutDownMessage={0}\r\n\r\n_shutDownStack={1}",

shutDownMessage,shutDownStack), "Application Shutdown",
youremail@xxxxxxxxxxxxx, null, null);

}



George



"SAL" <SAL@xxxxxxxxxxxxx> wrote in message
news:uVWu%23LYIIHA.4712@xxxxxxxxxxxxxxxxxxxxxxx
Okay, so let's say that all of the things you've listed below are not
happening. But, that a Response.Redirect may be. The documentation states
that Redirect calls End which raises a ThreadAbortException. I do not see
this exception however. I am wondering if this could be at the root of
my random problem here...

Thanks for your responses
S

"Peter Bromberg [C# MVP]" <pbromberg@xxxxxxxxxxxxxxxxxxxx> wrote in
message news:ACF43915-74F4-490B-9EEA-8F2E9629A3A3@xxxxxxxxxxxxxxxx
Sal,
The only time a Session item would be lost under "normal circumstances"
(e.g. it hasn't timed out by itself due to no page requests) is that IIS
is
recycling the application. Recycling can be because of IIS settings,
because
something touched one or more of the files in the web folder "tree", or
because you've got buggy code that's causing unhandled exceptions.
In any of these cases, you can bet that your Application, Session and
Cache
items will all go down the potty.
Peter
--
http://www.eggheadcafe.com
unBlog: http://petesbloggerama.blogspot.com
BlogMetaFinder: http://www.blogmetafinder.com



"SAL" wrote:

Mark, thanks for the reply.
I do not see either of these things applying here. This happened twice
this
morning for no apparent reason and then it didn't happen. I have not
changed
the time out so it should still be 20 minutes and I am not overwriting
them
as far as I can see. I can not reproduce it on my machine.

S

"Mark Rae [MVP]" <mark@xxxxxxxxxxxxxxxxx> wrote in message
news:%237xKnRMIIHA.5056@xxxxxxxxxxxxxxxxxxxxxxx
"SAL" <SAL@xxxxxxxxxxxxx> wrote in message
news:u5$G%23JMIIHA.4712@xxxxxxxxxxxxxxxxxxxxxxx

My question is, is there some reason that my session variable
evaporates
randomly?

No. Session variables will be lost when the Session times out, or
when
they are overwritten / removed - does either of these situations
apply
here...?


--
Mark Rae
ASP.NET MVP
http://www.markrae.net









.



Relevant Pages