469,923 Members | 1,627 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,923 developers. It's quick & easy.

2 Simple Questions About Session_Start

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.
Nov 18 '05 #1
6 2349
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

"Jeff Smythe" <Sm*******@YaRight.com> wrote in message
news:ew**************@TK2MSFTNGP12.phx.gbl...
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.

Nov 18 '05 #2
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

"Jerry Boone" <je***@antech.biz.killspam> wrote in message
news:WB********************@newssvr11.news.prodigy .com...
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

"Jeff Smythe" <Sm*******@YaRight.com> wrote in message
news:ew**************@TK2MSFTNGP12.phx.gbl...
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.


Nov 18 '05 #3
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" <je***@antech.biz.killspam> wrote in message
news:dH********************@newssvr11.news.prodigy .com...
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

"Jerry Boone" <je***@antech.biz.killspam> wrote in message
news:WB********************@newssvr11.news.prodigy .com...
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

"Jeff Smythe" <Sm*******@YaRight.com> wrote in message
news:ew**************@TK2MSFTNGP12.phx.gbl...
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.



Nov 18 '05 #4
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" <Sm*******@YaRight.com> wrote in message
news:O3**************@TK2MSFTNGP10.phx.gbl...
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" <je***@antech.biz.killspam> wrote in message
news:dH********************@newssvr11.news.prodigy .com...
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

"Jerry Boone" <je***@antech.biz.killspam> wrote in message
news:WB********************@newssvr11.news.prodigy .com...
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

"Jeff Smythe" <Sm*******@YaRight.com> wrote in message
news:ew**************@TK2MSFTNGP12.phx.gbl...
> 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.
>
>



Nov 18 '05 #5
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 theproblem 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" <Sm*******@YaRight.com> wrote in message
news:O3**************@TK2MSFTNGP10.phx.gbl...
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 haveobserved
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" <je***@antech.biz.killspam> wrote in message news:dH2Gb.108 $F***********@newssvr11.news.prodigy.com...
> By the way, sessions should only start once and keep a session id thatis
> 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 HomeDirectory-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
>
>
>
> "Jerry Boone" <je***@antech.biz.killspam> wrote in

message > news:WB2Gb.106 $G***********@newssvr11.news.prodigy.com... > > 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
> >
> >
> >
> > "Jeff Smythe" <Sm*******@YaRight.com> wrote in
message > > news:ew**************@TK2MSFTNGP12.phx.gbl...
> > > 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.
> > >
> > >
> >
> >
>
>


.

Nov 18 '05 #6
> >> > > > Why does Session_Start in Global.asax fire for a session of an
ASP.NET application?
> > > Am I wrong to expect that it would fire only when the first page

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
<an*******@discussions.microsoft.com> wrote in message
news:1b****************************@phx.gbl...
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" <Sm*******@YaRight.com> wrote in message
news:O3**************@TK2MSFTNGP10.phx.gbl...
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" <je***@antech.biz.killspam> wrote in message news:dH2Gb.108 $F***********@newssvr11.news.prodigy.com... > 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
>
>
>
> "Jerry Boone" <je***@antech.biz.killspam> wrote in

message > news:WB2Gb.106 $G***********@newssvr11.news.prodigy.com... > > 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
> >
> >
> >
> > "Jeff Smythe" <Sm*******@YaRight.com> wrote in message > > news:ew**************@TK2MSFTNGP12.phx.gbl...
> > > 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.
> > >
> > >
> >
> >
>
>

.

Nov 18 '05 #7

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by Florence HENRY | last post: by
2 posts views Thread by Reply-Via-Newsgroup Thanks | last post: by
1 post views Thread by Mercy | last post: by
5 posts views Thread by Niklas Uhlin | last post: by
5 posts views Thread by Logickle | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.