473,748 Members | 5,849 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 3853
Set Page.EnableSess ionstate="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*****@commun ity.nospamwrote in message news:dr******** *************** *********@4ax.c om...
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 EnableSessionSt ate 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
IRequiresSessio nState, IReadOnlySessio nState 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 IRequiresSessio nState or
IReadOnlySessio nState 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*****@commun ity.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 EnableSessionSt ate 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
IRequiresSessi onState, IReadOnlySessio nState 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 IRequiresSessio nState or
IReadOnlySessi onState 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.EnableSess ionstate="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.comwrot e in message
news:OE******** ******@TK2MSFTN GP03.phx.gbl...
Set Page.EnableSess ionstate="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*****@commun ity.nospamwrote in message
news:dr******** *************** *********@4ax.c om...
>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.En ableSessionStat e = PagesEnableSess ionState.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******** *************** ***********@mic rosoft.com...
You mean doing the same than with the EnableSessionSt ate 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 IRequiresSessio nState, IReadOnlySessio nState 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 IRequiresSessio nState or IReadOnlySessio nState 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*****@commun ity.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*****@comcas t.netwrote in message news:eI******** ******@TK2MSFTN GP04.phx.gbl...
>I am not sure at which stage you can set Page.EnableSess ionstate="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.comwrot e in message news:OE******** ******@TK2MSFTN GP03.phx.gbl...
>Set Page.EnableSess ionstate="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*****@commun ity.nospamwrote in message news:dr******** *************** *********@4ax.c om...
>>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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
2385
by: Greg Linwood | last post by:
I'm having difficulty understanding Session state in ASP.Net. It's almost embarrassing asking this as I've been using ASP since it was first released & it really shouldn't be this hard to use - perhaps I'm just not very smart or perhaps MS is making this too hard for us sql bunnies to understand - I dunno, but I'd really appreciate someone explaining what I'm doing wrong here & perhaps suggest a better approach.. I'm familiar with use of...
4
4006
by: John Q. Smith | last post by:
I'm trying to find out some of the details behind OOP state management with SQL Server. For instance - how long does the session object live on any server? Is it created and destoyed with each page request? - will each reading of a session variable cause a round trip to the DB server? or does the complete session live within the HttpContext object? - when asp.net session state is enabled (in any mode), after a session has been created,...
3
1559
by: moondaddy | last post by:
I'm writing a shopping cart in vb.net and for the first time I'm working with session state on the server. I'm using it to maintain the user's shopping cart for the session. in the browser is a datagrid with a listing of products. If I put a break point in the code behind the code execution will break at that point just as you would expect. When the user clicks on an item in the grid it executes a line of jscript listed below which...
5
1536
by: Arun | last post by:
Hi, Is it possible to share Session/Application State across different Asp.net webapplication (one in VB.net ) and the other is C# ? If so can you guide me ? -Regards' Arun
2
2009
by: Chris | last post by:
Hi, I am building a single webform/webpage asp.net application using VB.NET. I have created lots of classes for this web application. On page load I use a facade controller pattern class to perform all my initial class object instaniations using sub new() procedures I'm using this project to learn the ins and outs of OOA and OOD, so instead of doing everything in code behind pages I have lots of objects now created
12
7307
by: Thomas Andersson | last post by:
Hi, How can I access a session variable within a Public Class? I have tried the below code, but I get a server error "Object reference not set to an instance of an object". System.Web.HttpContext.Current.Session.Add("myKey", "myValue") Dim a As String a = System.Web.HttpContext.Current.Session.Item("myKey")
5
548
by: Sean | last post by:
Problem with sessions I have created an application without concern for sessions. As it turns out I think that might be my undoing. What I have: I have an online quiz. I don’t need to know users or save any data. If the application crashes or user exits the program they should simply start again. Pretty basic. All interactions are stored in an array (not much going on to save to a
2
2082
by: ras26 | last post by:
I have a WebSite "App1" which has an external assembly "Lib1". Inside this external assembly we have developed some classes that derive from "System.Web.UI.Page". One of these pages is called "WebNotification". In the WebSite "App1" we create an instance of "WebNotification", but when this class tries to access some Session variables it generates the following error: Session state can only be used when enableSessionState is set to...
3
4915
by: =?Utf-8?B?U2FjaGluIFNha2k=?= | last post by:
Hi, Our application have asp and .aspx pages, we need to redirect user from asp page to .aspx page and vice-versa and want to share session state b/w asp and asp.net. This could be achieved by storing the session state in database. I have few quires on this. 1) What happen if asp session and asp.net session time out limit is different ? for example asp session limit is 20 min. and asp.net session limit is 30 min. if user is navigated from...
0
8823
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9530
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9363
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9312
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9238
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6793
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6073
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4593
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3300
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.