N
Niklas Uhlin
Someone please explain why Session_Start fires multiple times /
retains SessionID values between sessions, when you open an ASP.NET
page from MS Word. For details of the problem, see below:
1. Create a new C# ASP.NET web application named "demo" and modify
Session_Start in Global.asax.cs as follows:
protected void Session_Start(Object sender, EventArgs e)
{
Response.Write("Session_Start event fired at "+
DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss<BR><BR>"));
}
2. Modify Page_Load in WebForm1.aspx.cs as follows:
private void Page_Load(object sender, System.EventArgs e)
{
Response.Write("SESSION ID = "+ Session.SessionID +"<BR><BR>");
Response.Write("<A HREF=\"WebForm1.aspx\">Reload
page</A><BR><BR>");
}
3. Build the project.
4. Open Internet Explorer and navigate to
http://localhost/demo/WebForm1.aspx.
You should see the following text:
Session_Start event fired at <YYYY-MM-DD HH:MM:SS>
Session Id = <XXX>
And if you click the "reload page" link, the "Session_Start" text
should disappear (because Session_Start has already been fired). The
"Session Id" text, however, should remain and have the same value
(because we're still in the same session).
Now, that is how it *should* be working. However, if you close all
Internet Explorer windows and replace step 4 with the following,
that's when things start to behave really weird...
1. If Microsoft Word 2002 is open – exit the program.
2. If Internet Explorer is open – exit the program.
3. Open Microsoft Word 2002
4. Type the following into a new document:
http://localhost/demo/WebForm1.aspx.
5. Click the link, thereby opening WebForm1.aspx in a new Internet
Explorer window.
6. Notice how Session_Start fires and how you're assigned a Session
Id.
7. Now click the "reload page" link and notice how Session_Start is
fired again(!) and how you're assigned a brand new Session Id(!) even
though the page is reloaded in the same Internet Explorer window!
Another, even more interesting twist to the same problem surfaces if
you replace step 4 with the following:
1. If Microsoft Word 2002 is open – exit the program.
2. If Internet Explorer is open – exit the program.
3. Open Microsoft Word 2002
4. Type the following into a new document:
http://localhost/demo/WebForm1.aspx.
5. Click the link, thereby opening WebForm1.aspx in a new Internet
Explorer window.
6. Notice how Session_Start fires and how you're assigned a Session Id
(write down these values for comparison later on).
7. Now click the "reload page" link and notice how Session_Start is
fired again(!) and how you're assigned a brand new Session Id(!) even
though the page is reloaded in the same Internet Explorer window
(write down these values for comparison later on)!
8. Close Internet Explorer but leave Microsoft Word 2002 running.
9. Click the link again, thereby opening WebForm1.aspx in a new
Internet Explorer window.
10. Notice how Session_Start *appears* to fire anew, but how both the
time stamp and the Session Id retain the values as before you closed
Internet Explorer!
What the heck is going on here?
Brgds,
Niklas Uhlin
System Developer
CSC
retains SessionID values between sessions, when you open an ASP.NET
page from MS Word. For details of the problem, see below:
1. Create a new C# ASP.NET web application named "demo" and modify
Session_Start in Global.asax.cs as follows:
protected void Session_Start(Object sender, EventArgs e)
{
Response.Write("Session_Start event fired at "+
DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss<BR><BR>"));
}
2. Modify Page_Load in WebForm1.aspx.cs as follows:
private void Page_Load(object sender, System.EventArgs e)
{
Response.Write("SESSION ID = "+ Session.SessionID +"<BR><BR>");
Response.Write("<A HREF=\"WebForm1.aspx\">Reload
page</A><BR><BR>");
}
3. Build the project.
4. Open Internet Explorer and navigate to
http://localhost/demo/WebForm1.aspx.
You should see the following text:
Session_Start event fired at <YYYY-MM-DD HH:MM:SS>
Session Id = <XXX>
And if you click the "reload page" link, the "Session_Start" text
should disappear (because Session_Start has already been fired). The
"Session Id" text, however, should remain and have the same value
(because we're still in the same session).
Now, that is how it *should* be working. However, if you close all
Internet Explorer windows and replace step 4 with the following,
that's when things start to behave really weird...
1. If Microsoft Word 2002 is open – exit the program.
2. If Internet Explorer is open – exit the program.
3. Open Microsoft Word 2002
4. Type the following into a new document:
http://localhost/demo/WebForm1.aspx.
5. Click the link, thereby opening WebForm1.aspx in a new Internet
Explorer window.
6. Notice how Session_Start fires and how you're assigned a Session
Id.
7. Now click the "reload page" link and notice how Session_Start is
fired again(!) and how you're assigned a brand new Session Id(!) even
though the page is reloaded in the same Internet Explorer window!
Another, even more interesting twist to the same problem surfaces if
you replace step 4 with the following:
1. If Microsoft Word 2002 is open – exit the program.
2. If Internet Explorer is open – exit the program.
3. Open Microsoft Word 2002
4. Type the following into a new document:
http://localhost/demo/WebForm1.aspx.
5. Click the link, thereby opening WebForm1.aspx in a new Internet
Explorer window.
6. Notice how Session_Start fires and how you're assigned a Session Id
(write down these values for comparison later on).
7. Now click the "reload page" link and notice how Session_Start is
fired again(!) and how you're assigned a brand new Session Id(!) even
though the page is reloaded in the same Internet Explorer window
(write down these values for comparison later on)!
8. Close Internet Explorer but leave Microsoft Word 2002 running.
9. Click the link again, thereby opening WebForm1.aspx in a new
Internet Explorer window.
10. Notice how Session_Start *appears* to fire anew, but how both the
time stamp and the Session Id retain the values as before you closed
Internet Explorer!
What the heck is going on here?
Brgds,
Niklas Uhlin
System Developer
CSC