2 Simple Questions About Session_Start

  • Thread starter Thread starter Jeff Smythe
  • Start date Start date
J

Jeff Smythe

Why does Session_Start in Global.asax fire for every page opened during a
session of an ASP.NET application?

Am I wrong to expect that it would fire only when the first page (i.e., any
page in the app that is opened before any other page during the session) is
opened?

Thanks.
 
Sounds like you have....

sessionState mode="Off"

in web.config

or possibly you have this in your page directives <%@ Page...
EnableSessionState="ReadOnly"...

Let me know what you find? Ok?


--
Jerry Boone
Analytical Technologies, Inc.
http://www.antech.biz
Secure Hosting and Development Solutions for ASP, ASP.NET, SQL Server, and
Access
 
By the way, sessions should only start once and keep a session id that is
accessible by doing response.write(session.sessionid)

The start event will only fire once for the length of your session which is
determined in IIS under your websites Home Directory-Configuration-Options
(default is 20 minutes). Once that expires and your user clicks something,
they will trip the start event and get a new session id, which is bad if you
rely on session variables to store the data in server RAM. Hence, the
improvements to use a state server, sql server, and other ways to maintain
state.

--
Jerry Boone
Analytical Technologies, Inc.
http://www.antech.biz
Secure Hosting and Development Solutions for ASP, ASP.NET, SQL Server, and
Access
 
I checked three things as you suggested - and everything looks good:
1. WebConfig does not have the following entry: [sessionState mode="Off"]
Rather, mode is "InProc"
2. The pages in question do not have the following directive: [@
Page...EnableSessionState="ReadOnly"...]
3. IIS Configuration has the defaults [Enable Session State] checked, with
the timeout default of 20 minutes.

When I add the following line to Session_Start
Response.Write(Session.SessionID);
I get a different value for SessionID on every successive page I open. It
even happens for my login page when I enter invalid credentials and it
simply redisplays the same page. This tells me that it is actually starting
a new session for each page sent to the browser.

FWIW, I'm using VS.NET 2003 on WinXP Pro/SP1, clean install, machine is
stable, IIS is running with defaults installation settings. I have observed
this behavior on two different ASP.NET applications I'm developing on this
machine. Both are C# and use code-behind modules.

Any other ideas?

I really appreciate the help - don't know what else to look at.

-Jeff
 
Anybody have any other ideas? Still having the problem.

If you read only the first sentence of my last reply, it may appear that the
problem is solved - but it's not. That first sentence should continue ...
"everything looks good -but the problem persists..."

I'd appreciate any additional suggestions.




Jeff Smythe said:
I checked three things as you suggested - and everything looks good:
1. WebConfig does not have the following entry: [sessionState mode="Off"]
Rather, mode is "InProc"
2. The pages in question do not have the following directive: [@
Page...EnableSessionState="ReadOnly"...]
3. IIS Configuration has the defaults [Enable Session State] checked, with
the timeout default of 20 minutes.

When I add the following line to Session_Start
Response.Write(Session.SessionID);
I get a different value for SessionID on every successive page I open. It
even happens for my login page when I enter invalid credentials and it
simply redisplays the same page. This tells me that it is actually starting
a new session for each page sent to the browser.

FWIW, I'm using VS.NET 2003 on WinXP Pro/SP1, clean install, machine is
stable, IIS is running with defaults installation settings. I have observed
this behavior on two different ASP.NET applications I'm developing on this
machine. Both are C# and use code-behind modules.

Any other ideas?

I really appreciate the help - don't know what else to look at.

-Jeff


Jerry Boone said:
By the way, sessions should only start once and keep a session id that is
accessible by doing response.write(session.sessionid)

The start event will only fire once for the length of your session which is
determined in IIS under your websites Home Directory-Configuration-Options
(default is 20 minutes). Once that expires and your user clicks something,
they will trip the start event and get a new session id, which is bad if you
rely on session variables to store the data in server RAM. Hence, the
improvements to use a state server, sql server, and other ways to maintain
state.

--
Jerry Boone
Analytical Technologies, Inc.
http://www.antech.biz
Secure Hosting and Development Solutions for ASP, ASP.NET, SQL Server, and
Access



during
 
I have the same problem, My project run on a server with 4
cpu. and when I set mode to stateserver, it's ok, but I
need set some come to session, that don't support by
stateserver.
-----Original Message-----
Anybody have any other ideas? Still having the problem.

If you read only the first sentence of my last reply, it may appear that the
problem is solved - but it's not. That first sentence should continue ...
"everything looks good -but the problem persists..."

I'd appreciate any additional suggestions.




Jeff Smythe said:
I checked three things as you suggested - and everything looks good:
1. WebConfig does not have the following entry: [sessionState mode="Off"]
Rather, mode is "InProc"
2. The pages in question do not have the following directive: [@
Page...EnableSessionState="ReadOnly"...]
3. IIS Configuration has the defaults [Enable Session State] checked, with
the timeout default of 20 minutes.

When I add the following line to Session_Start
Response.Write(Session.SessionID);
I get a different value for SessionID on every successive page I open. It
even happens for my login page when I enter invalid credentials and it
simply redisplays the same page. This tells me that it
is actually
starting
a new session for each page sent to the browser.

FWIW, I'm using VS.NET 2003 on WinXP Pro/SP1, clean install, machine is
stable, IIS is running with defaults installation
settings. I have
observed
this behavior on two different ASP.NET applications I'm developing on this
machine. Both are C# and use code-behind modules.

Any other ideas?

I really appreciate the help - don't know what else to look at.

-Jeff
a session id that
is
your session which
is user clicks
something, id, which is bad if
you
other ways to
maintain ASP.NET, SQL Server,
and
ASP.NET, SQL Server,
and every page opened
during the first page
(i.e., page during the
session)


.
 
Why does Session_Start in Global.asax fire for a session of an
ASP.NET application?
Technically, yes you are wrong. It's not necessarily for the first page but
rather session start fires for each new session id generated. That this
happens as a result of a new page request is really coincidental.

Session state is necessarily complex because of the need to service
different state providers. It is possible to have session id be regenerated
for each page within the same application even if the user does not close
the browser or log out - like what you are experiencing. This is by design.
The run-time checks the session dictionary object to determine if it is
written to. If it is not, it generates a new session id which in term fires
the session start event. If it is written to, then the existing session id
is used to service the request. Notice, this isn't page dependent at all.

To plug this behavior, you would need to write an arbitrary value to
session: session["null"] = null; You will then have this session id until
the browser is closed. Calling session abandon or session end will not
reassign a new session id. And session start will be guaranteed to only fire
once within this context.

--
Regards,
Alvin Bruney
Got DotNet? Get it here
http://home.networkip.net/dotnet/tidbits/default.htm
I have the same problem, My project run on a server with 4
cpu. and when I set mode to stateserver, it's ok, but I
need set some come to session, that don't support by
stateserver.
-----Original Message-----
Anybody have any other ideas? Still having the problem.

If you read only the first sentence of my last reply, it may appear that the
problem is solved - but it's not. That first sentence should continue ...
"everything looks good -but the problem persists..."

I'd appreciate any additional suggestions.




Jeff Smythe said:
I checked three things as you suggested - and everything looks good:
1. WebConfig does not have the following entry: [sessionState mode="Off"]
Rather, mode is "InProc"
2. The pages in question do not have the following directive: [@
Page...EnableSessionState="ReadOnly"...]
3. IIS Configuration has the defaults [Enable Session State] checked, with
the timeout default of 20 minutes.

When I add the following line to Session_Start
Response.Write(Session.SessionID);
I get a different value for SessionID on every successive page I open. It
even happens for my login page when I enter invalid credentials and it
simply redisplays the same page. This tells me that it
is actually
starting
a new session for each page sent to the browser.

FWIW, I'm using VS.NET 2003 on WinXP Pro/SP1, clean install, machine is
stable, IIS is running with defaults installation
settings. I have
observed
this behavior on two different ASP.NET applications I'm developing on this
machine. Both are C# and use code-behind modules.

Any other ideas?

I really appreciate the help - don't know what else to look at.

-Jeff


[email protected]...
By the way, sessions should only start once and keep
a session id that
is
accessible by doing response.write (session.sessionid)

The start event will only fire once for the length of your session which
is
determined in IIS under your websites Home Directory-Configuration-Options
(default is 20 minutes). Once that expires and your user clicks
something,
they will trip the start event and get a new session id, which is bad if
you
rely on session variables to store the data in server RAM. Hence, the
improvements to use a state server, sql server, and
other ways to
maintain
state.

--
Jerry Boone
Analytical Technologies, Inc.
http://www.antech.biz
Secure Hosting and Development Solutions for ASP,
ASP.NET, SQL Server,
and
Access



[email protected]...
Sounds like you have....

sessionState mode="Off"

in web.config

or possibly you have this in your page directives <% @ Page...
EnableSessionState="ReadOnly"...

Let me know what you find? Ok?


--
Jerry Boone
Analytical Technologies, Inc.
http://www.antech.biz
Secure Hosting and Development Solutions for ASP, ASP.NET, SQL Server,
and
Access



Why does Session_Start in Global.asax fire for every page opened
during
a
session of an ASP.NET application?

Am I wrong to expect that it would fire only when the first page
(i.e.,
any
page in the app that is opened before any other page during the
session)
is
opened?

Thanks.


.
 
Back
Top