469,621 Members | 1,802 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

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

Disable Session State in Code Behind?

Using ASP.NET 2.0, I want to use the code-behind to disable session
state (eg I do not want to put anything in the .aspx page template). I
also do not want to touch web.config.

How can I do this?

Thanks.
Jul 10 '08 #1
6 3652
Set Page.EnableSessionstate="false" in the code-behind.


Juan T. Llibre, asp.net MVP
asp.net faq : http://asp.net.do/faq/
foros de asp.net, en español : http://asp.net.do/foros/
======================================
"coconet" <co*****@community.nospamwrote in message news:dr********************************@4ax.com...
Using ASP.NET 2.0, I want to use the code-behind to disable session
state (eg I do not want to put anything in the .aspx page template). I
also do not want to touch web.config.

How can I do this?

Thanks.


Jul 10 '08 #2
You mean doing the same than with the EnableSessionState page directive ?

IMO you can't from the page code-behind as your page is already running and
so ASP.NET needed already to know wether session should be activated or not
for this page... This might be possible using a ( stop !!).

Gave a look and found :
http://www.15seconds.com/issue/020417.htm

It looks to be done at compile time by using or not the
IRequiresSessionState, IReadOnlySessionState interfaces so you could declare
this from your code behind. I tried, it works.

Strickly speaking you can't do this without touching web.config as it
doesn't seem you can tell that session is not required at all (likely the
"false" value allows to suppress the addition of those interfaces but you
have no way to do that if session are already enabled in the web config as
the absence of the directive will cause the appropriate interface to be
added for you).

So the best you could do for now would be :
- to suppress session in the web.config
- you can add session support by using IRequiresSessionState or
IReadOnlySessionState in your code behind file

You may want still to elaborate about what you are trying to do and why the
page directive doesn't fit...

--
Patrice

"coconet" <co*****@community.nospama écrit dans le message de groupe de
discussion : dr********************************@4ax.com...
Using ASP.NET 2.0, I want to use the code-behind to disable session
state (eg I do not want to put anything in the .aspx page template). I
also do not want to touch web.config.

How can I do this?

Thanks.

Jul 10 '08 #3

Thanks for the help. I wanted to avoid touching the .aspx to keep all
changes, etc in a unit-testable .cs file. I'll just live with it in
the .aspx for now.

Thanks.
On Thu, 10 Jul 2008 19:46:41 +0200, "Patrice"
<http://www.chez.com/scribe/wrote:
>You mean doing the same than with the EnableSessionState page directive ?

IMO you can't from the page code-behind as your page is already running and
so ASP.NET needed already to know wether session should be activated or not
for this page... This might be possible using a ( stop !!).

Gave a look and found :
http://www.15seconds.com/issue/020417.htm

It looks to be done at compile time by using or not the
IRequiresSessionState, IReadOnlySessionState interfaces so you could declare
this from your code behind. I tried, it works.

Strickly speaking you can't do this without touching web.config as it
doesn't seem you can tell that session is not required at all (likely the
"false" value allows to suppress the addition of those interfaces but you
have no way to do that if session are already enabled in the web config as
the absence of the directive will cause the appropriate interface to be
added for you).

So the best you could do for now would be :
- to suppress session in the web.config
- you can add session support by using IRequiresSessionState or
IReadOnlySessionState in your code behind file

You may want still to elaborate about what you are trying to do and why the
page directive doesn't fit...
Jul 10 '08 #4
I am not sure at which stage you can set Page.EnableSessionstate="false"
(for it to make sense)
I have a feeling that you can do that only in constructor to work....

Obviously on Render even it will be too late to do that. Because the Session
module already kicked in...
If someone has some clarification on that it would be good.

George.

"Juan T. Llibre" <no***********@nowhere.comwrote in message
news:OE**************@TK2MSFTNGP03.phx.gbl...
Set Page.EnableSessionstate="false" in the code-behind.


Juan T. Llibre, asp.net MVP
asp.net faq : http://asp.net.do/faq/
foros de asp.net, en español : http://asp.net.do/foros/
======================================
"coconet" <co*****@community.nospamwrote in message
news:dr********************************@4ax.com...
>Using ASP.NET 2.0, I want to use the code-behind to disable session
state (eg I do not want to put anything in the .aspx page template). I
also do not want to touch web.config.

How can I do this?

Thanks.


Jul 10 '08 #5
re:
!IMO you can't from the page code-behind as your page is already running

Wouldn't this code, in Page_Init, do the trick ?

pagesSection.EnableSessionState = PagesEnableSessionState.False


Juan T. Llibre, asp.net MVP
asp.net faq : http://asp.net.do/faq/
foros de asp.net, en español : http://asp.net.do/foros/
======================================
"Patrice" <http://www.chez.com/scribe/wrote in message news:1E**********************************@microsof t.com...
You mean doing the same than with the EnableSessionState page directive ?

IMO you can't from the page code-behind as your page is already running and so ASP.NET needed already to know wether
session should be activated or not for this page... This might be possible using a ( stop !!).

Gave a look and found :
http://www.15seconds.com/issue/020417.htm

It looks to be done at compile time by using or not the IRequiresSessionState, IReadOnlySessionState interfaces so you
could declare this from your code behind. I tried, it works.

Strickly speaking you can't do this without touching web.config as it doesn't seem you can tell that session is not
required at all (likely the "false" value allows to suppress the addition of those interfaces but you have no way to
do that if session are already enabled in the web config as the absence of the directive will cause the appropriate
interface to be added for you).

So the best you could do for now would be :
- to suppress session in the web.config
- you can add session support by using IRequiresSessionState or IReadOnlySessionState in your code behind file

You may want still to elaborate about what you are trying to do and why the page directive doesn't fit...

--
Patrice

"coconet" <co*****@community.nospama écrit dans le message de groupe de discussion :
dr********************************@4ax.com...
>Using ASP.NET 2.0, I want to use the code-behind to disable session
state (eg I do not want to put anything in the .aspx page template). I
also do not want to touch web.config.

How can I do this?

Thanks.


Jul 10 '08 #6
re:
!I have a feeling that you can do that only in constructor to work....

I *know* that in the constructor you can't do it.
I haven't tested, but it would seem to me that in Page_Init it should work.

I'll try to set up a test scenario to test this.


Juan T. Llibre, asp.net MVP
asp.net faq : http://asp.net.do/faq/
foros de asp.net, en español : http://asp.net.do/foros/
======================================
"George" <no*****@comcast.netwrote in message news:eI**************@TK2MSFTNGP04.phx.gbl...
>I am not sure at which stage you can set Page.EnableSessionstate="false" (for it to make sense)
I have a feeling that you can do that only in constructor to work....

Obviously on Render even it will be too late to do that. Because the Session module already kicked in...
If someone has some clarification on that it would be good.

George.

"Juan T. Llibre" <no***********@nowhere.comwrote in message news:OE**************@TK2MSFTNGP03.phx.gbl...
>Set Page.EnableSessionstate="false" in the code-behind.


Juan T. Llibre, asp.net MVP
asp.net faq : http://asp.net.do/faq/
foros de asp.net, en español : http://asp.net.do/foros/
======================================
"coconet" <co*****@community.nospamwrote in message news:dr********************************@4ax.com...
>>Using ASP.NET 2.0, I want to use the code-behind to disable session
state (eg I do not want to put anything in the .aspx page template). I
also do not want to touch web.config.

How can I do this?

Thanks.



Jul 10 '08 #7

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

9 posts views Thread by Greg Linwood | last post: by
4 posts views Thread by John Q. Smith | last post: by
3 posts views Thread by moondaddy | last post: by
5 posts views Thread by Arun | last post: by
12 posts views Thread by Thomas Andersson | last post: by
5 posts views Thread by Sean | last post: by
3 posts views Thread by =?Utf-8?B?U2FjaGluIFNha2k=?= | last post: by
reply views Thread by devrayhaan | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.