View Full Version : Session end
TonyMast
08-03-2004, 11:00 AM
I would like to test the session_end event in the global.asa.
Can amyone give me some good test code to see if it's firing? Everything i do dosn't fire.
Thank you
Tony
bruce
08-03-2004, 11:08 AM
just call session.end.
[b]quote:Originally posted by TonyMast
I would like to test the session_end event in the global.asa.
Can amyone give me some good test code to see if it's firing? Everything i do dosn't fire.
Thank you
Tony
</blockquote id="quote"></font id="quote">
TonyMast
08-04-2004, 07:33 AM
Yes, I use session.abandon there is no session.end. I'm using visual studio 2002 and vb .net web project.
I was looking for code i could place in the session_end event that would show me that it fired.
Thanks
Thank you
Tony
bruce
08-05-2004, 03:49 AM
ah.. thank you for correcting me.. i didn't check the reference, just came straight out from memory.
[b]quote:Originally posted by TonyMast
Yes, I use session.abandon there is no session.end. I'm using visual studio 2002 and vb .net web project.
I was looking for code i could place in the session_end event that would show me that it fired.
Thanks
Thank you
Tony
</blockquote id="quote"></font id="quote">
Malin
08-07-2004, 07:37 AM
Hi tonyMast
First I want to say sorry if I'm getting to basic [:)]
If I were you I would first try the following:
Put any code into session_end in global.asax, for example:
string str = "this is a test"; (this is c# code, if you are using VB then just translate)
Then you have to check if the session_end event is really firing as it should. To do this you can put "session.abandon" in your code in a location where you know it will be executed. I have understood that you use VS as development environment (so do I) and there is a simple test you can do to be sure about the session_end event being fired or not. Simply place cursor on the code you have put in the session_end event in global.asax, then right click and from popup menu choose "run to cursor".
Now your program will begin to execute and if session_end event is firing as it should then program execution will pause and step into debug-mode just as the session object dies due to your code "session.abandon". If this does not happen then the event is not fired and the code in global.asax session_end event is not triggered.
If the session_end event is not triggering then I would try to execute the application from outside and independent of Visual Studio. I once made a shopping site in java/jdeveloper and I ran into the problem of session not dying although I killed it. This gave me a lot of extra job and I was really tired about the whole thing when I tried to upload files to Tomcat and ran application from there. Everything worked like a charm. I cannot see any other explanaition than jdeveloper stopped the session from dying even when I explicetly killed session object.
Since this expirience I have this feeling that perhaps it is not best to run applications within development applications when working on session related tasks. I rather run session tests directly on webserver.
I cannot say that the problem exists in Visual Studio, but it sure does in jdeveloper 9i, but since the test is quick I would go for it.
Malin
TonyMast
08-09-2004, 09:06 AM
Thanks again milan.
The page_load event fires.
I should have explained it better sorry.
I'm using VS vb .net and web forms so I don't know if i can start debug process remotely with the run to cursor.
I used the run to cursor in the page_load b/c I knew that worked and i wanted to see what happens when I "run to cursor" in an event I know fires.
Thanks for help anyway. I pretty well convinced that the seesion_end is not firing and I have something set wrong.
Thank you
Tony
TonyMast
08-09-2004, 10:29 AM
Thanks Milan,
It isn't to basic for me exspecially when i can't get it to work.
I tried your suggestion and nothing happened. I also did a "run to cursor" in the page load event of default.aspx and nothing happened either so maybe i'm using the "run to cursor " wrong.
but i'm pretty sure that the session_end event is not firing, i put some code in it that I know works that adds a record to a database and no record is ever added.
I.ve tried both from VS and directly calling the page on the server with IE6.
Still not firing.
Thank you
Tony
Malin
08-09-2004, 12:25 PM
OK...
I really think I know the answer to your problem.
If I understand you right then not even page_load in your start page fires.
If this is right then you have to look in the code behind for your startpage and expand the node where you see the text:
"#region Web Form Designer generated code"
This is code Visual Studio automatically develops for youe application. In this code there is supposed to be an eventhandler for the page_load event. An eventhandler is a listener who is listneing for a specific event. You have to subscribe for this to work and the code for this is the following:
"this.Load += new System.EventHandler(this.Page_Load);"
The code line above means that when "this" (the object in question is called "this" in C#) loads, the eventhandler is supposed to run method page_load in "this" (in this case "this" is your startpage).
The line above subscribes the method Page_load to the listner and when page loads it will notify its subscribers.
If this line is not present in your code your application will appear dead. This has happened many times to me in VS - dont know why VS do this but this is the draw back with advanced development environments - they help a lot but they also confuses, produce to much useless code and sometimes removes code without you knowing it. You can do a small misstake and you think you have corrected it - but VS maybe already has removed some code and will not reinsert it.
The whole section of code in "#region Web Form Designer generated code" looks like this (if you and/or VS have not inserted a lot of other code):
#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
InitializeComponent();
base.OnInit(e);
}
private void InitializeComponent()
{
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
I think "this" is called "Me" in vb.net but I'm not sure about it since the only VB version I know is vb 6 and this is not an object oriented language like vb.net.
I really hope this is the problem you are having. Otherwise - post your code [:)]. I really dont think there is something wrong in the "run to cursor". Since event is not fired the run to cursor point is never reached so the debug-mode will never start. Lets hope you will get this going and then you can try run to cursor again in page_load to see how it works. When debug starts - step forward in the code by pressing F10 (I guess this is same even though I have Swedish keyboard).
Good luck [:)]
TonyMast
08-11-2004, 02:56 AM
Thanks Milin
So sorry about the error in name. [V]
I tried using the session_start and works perfectly and as expected.
put same exact code into session_end and nothing.
I suspect your original observation was correct the seesion is not being ended either by the server settings or by my web config settings or some other seeting. I'm sure (pretty sure) that discountasp.net (hosting provider) has there server seetings correct or others would have complained. So I'm doing something worng!
Also thanks to Bruce.
Thank you
Tony
Malin
08-11-2004, 05:05 AM
Try to let the session timeout instead.
Use a textbox and two buttons in a page.
One button places a string in the sessionobject.
The other button takes the string out of the sessionobject and prints it to the textbox.
Then you run application. Press first button to put string in sessionobject. Then wait patiently for 30 minutes then press second button. If session is dead there will be an error, or at least the string in sessionobject will not show up in the textbox. Then you can experiment with this..for example kill the sessionobject insted of letting it time out ..and so on.
Code ex:
to put a string in session object (this code goes in method/sub button1_click):
Session["testVariable"] = "testing"
To print the string from session object (this code goes in method/sub button2_click):
txtSessionString.Text = Session["testVariable"].ToString()
Hope this maybe helps you in some way.
Malin
Malin
08-11-2004, 05:26 AM
[b]quote:Originally posted by bruce
Setting up debugging locally is tough enough.
It is not possible to debug with a remote server unless you have admin access.
If i really need debugging, i create a little test project with WinForm or console app and debug it there.
</blockquote id="quote"></font id="quote">
Are you using Visual Studio? I do and I dont find it difficult to use the debugger. I have reinstalled VS many times and I have used both VS 2001 (or whatever the version was) and VS 2003 and I have never had any problems with debugging. Many other problems [:D] but not with debugging. It has been install and start debugging without problems.
IIS must be installed though and that may be somewhat tricky if you install it after the .net framework (or was it the other way around [?]). But when IIS is set up right and debugmode is set to true in webconfig it is just to start debugging with Visual Studios powerful debug tools.
When installing Visual Studio it automatically sets up an user account in XP with the name SQLDebugger. This account is not present on XP login screen, just in the controlpanel/accounts window.
Debug is very important to me. To step into program or setting breakpoints and follow all variables and controls values in locals window and so on.. it is perfect.
Thanks for the info about "remote debugging". I didnt know that but it seems logical that this requires admin access.
Malin
Malin
08-11-2004, 06:59 AM
>>Thanks again milan.
Not Milan, but Malin.. I'm a girl [8D]
>>The page_load event fires.
Ok - I Missunderstood you
>>I'm using VS vb .net and web forms so I don't know if i can start >>debug process remotely with the run to cursor.
Oh, this is news to me. It cant be possible that the debug capabilities are lost when you work remotely? I have never tested this but I would never develop applications in a way where I cant debug since this is a very important feature for me. There must be some way to start debug-mode even when you work remotely...at least I hope so. Is debug mode set to true in web.config?
>>Thanks for help anyway. I pretty well convinced that the >>seesion_end is not firing and I have something set wrong.
Test some other method in global.asax. I have this code in one of my applications.
In global.asax:
---------------------------------
protected void Application_BeginRequest(Object sender, EventArgs e)
{
if(Request.Url.ToString().IndexOf("localhost") > 0)
Application.Add("path", Request.ApplicationPath);
else
Application.Add("path", Request.PathInfo);
}
-------------------------------------
It works for me. By the way, my code is handling the changes in paths depending on if application is executing on localhost or other server. Strangely the request.applicationpath return correct path on my localhost but on discount it returns totally wrong path (it doesnt include "http://www ..." as it does when running on my localhost).
The above code sets the correct path depending on if server is localhost or other. It works fine and event fires as it should.
Malin
bruce
08-11-2004, 12:13 PM
Setting up debugging locally is tough enough.
It is not possible to debug with a remote server unless you have admin access.
If i really need debugging, i create a little test project with WinForm or console app and debug it there.
[b]quote:Originally posted by Malin
>>Thanks again milan.
Not Milan, but Malin.. I'm a girl [8D]
>>The page_load event fires.
Ok - I Missunderstood you
>>I'm using VS vb .net and web forms so I don't know if i can start >>debug process remotely with the run to cursor.
Oh, this is news to me. It cant be possible that the debug capabilities are lost when you work remotely? I have never tested this but I would never develop applications in a way where I cant debug since this is a very important feature for me. There must be some way to start debug-mode even when you work remotely...at least I hope so. Is debug mode set to true in web.config?
>>Thanks for help anyway. I pretty well convinced that the >>seesion_end is not firing and I have something set wrong.
Test some other method in global.asax. I have this code in one of my applications.
In global.asax:
---------------------------------
protected void Application_BeginRequest(Object sender, EventArgs e)
{
if(Request.Url.ToString().IndexOf("localhost") > 0)
Application.Add("path", Request.ApplicationPath);
else
Application.Add("path", Request.PathInfo);
}
-------------------------------------
It works for me. By the way, my code is handling the changes in paths depending on if application is executing on localhost or other server. Strangely the request.applicationpath return correct path on my localhost but on discount it returns totally wrong path (it doesnt include "http://www ..." as it does when running on my localhost).
The above code sets the correct path depending on if server is localhost or other. It works fine and event fires as it should.
Malin
</blockquote id="quote"></font id="quote">
B.
DiscountASP.NET
http://www.DiscountASP.NET
blabberblog
08-12-2004, 10:15 AM
For running on your local machine you can do the following:
Put some simple code like int x = 2; in the session end and set a breakpoint on it.
Run the app in debug mode when the session end gets called it will break at the breakpoint.
theprince
09-02-2004, 04:36 AM
hi
if you want to firing the session_end event
you should store some values in session
after that you call session.abandon
i think , it will work
by
the prince
vBulletin® ©Jelsoft Enterprises Ltd.