473,386 Members | 1,799 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

The Property Page.Session

Nad
Good day,

I have a question about the Page.Session property used in ASP.NET

This property is defined as follows:
public virtual HttpSessionState Session {get;}

and HttpSessionState is a sealed class derived from System.Object and it has
two indexers one integer and on string. For example the following code can be
used to set a Session variable in a web page.

Page.Session["myPage"] = new aClass();

and then it can be retrieved as follows:
aClass ac = (aClass)Page.Session["myPage"];

I will really help if someone could explain how this is possible.
Page.Session is a readonly property afterall. Another thing I don't
understand is that how can you treat Page.Session as an indexer?

I appreciate any clarification.

Nov 16 '05 #1
2 6768
Page.Session refers to the Session object of the current HttpContext, as
defined by HttpContext.Current.Session.

1. The Page.Session property is read only. You cannot change the
HttpContext.Session object associated with the page. That does not mean
that you can't change the properties of the Session object, only that you
can't change which Session object goes with the page.

2. Session is not an indexer, but it has an indexer - two indexers,
actually. One indexer that takes an integer parameter and returns the
Session.Items[value] object.

There is a second indexer that takes a string and, internally, finds the
Session.Item that matches the parameter string and then returns the object
associated with that item.

3. Indexers can be read only, and provide the behaviors as listed above,
or, as in the case of the indexers of the Session object, can be read/write.
When assigning a value, the indexer identifies the appropriate Session.Item
based on the integer index or the string name, creates it if it doesn't
already exist, and assigns the value to it.

HTH

DalePres
MCAD, MCDBA, MCSE

"Nad" <Na*@discussions.microsoft.com> wrote in message
news:62**********************************@microsof t.com...
Good day,

I have a question about the Page.Session property used in ASP.NET

This property is defined as follows:
public virtual HttpSessionState Session {get;}

and HttpSessionState is a sealed class derived from System.Object and it
has
two indexers one integer and on string. For example the following code can
be
used to set a Session variable in a web page.

Page.Session["myPage"] = new aClass();

and then it can be retrieved as follows:
aClass ac = (aClass)Page.Session["myPage"];

I will really help if someone could explain how this is possible.
Page.Session is a readonly property afterall. Another thing I don't
understand is that how can you treat Page.Session as an indexer?

I appreciate any clarification.

Nov 16 '05 #2
Nad
Got it. I appreciate your help.

"DalePres" wrote:
Page.Session refers to the Session object of the current HttpContext, as
defined by HttpContext.Current.Session.

1. The Page.Session property is read only. You cannot change the
HttpContext.Session object associated with the page. That does not mean
that you can't change the properties of the Session object, only that you
can't change which Session object goes with the page.

2. Session is not an indexer, but it has an indexer - two indexers,
actually. One indexer that takes an integer parameter and returns the
Session.Items[value] object.

There is a second indexer that takes a string and, internally, finds the
Session.Item that matches the parameter string and then returns the object
associated with that item.

3. Indexers can be read only, and provide the behaviors as listed above,
or, as in the case of the indexers of the Session object, can be read/write.
When assigning a value, the indexer identifies the appropriate Session.Item
based on the integer index or the string name, creates it if it doesn't
already exist, and assigns the value to it.

HTH

DalePres
MCAD, MCDBA, MCSE

"Nad" <Na*@discussions.microsoft.com> wrote in message
news:62**********************************@microsof t.com...
Good day,

I have a question about the Page.Session property used in ASP.NET

This property is defined as follows:
public virtual HttpSessionState Session {get;}

and HttpSessionState is a sealed class derived from System.Object and it
has
two indexers one integer and on string. For example the following code can
be
used to set a Session variable in a web page.

Page.Session["myPage"] = new aClass();

and then it can be retrieved as follows:
aClass ac = (aClass)Page.Session["myPage"];

I will really help if someone could explain how this is possible.
Page.Session is a readonly property afterall. Another thing I don't
understand is that how can you treat Page.Session as an indexer?

I appreciate any clarification.


Nov 16 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Henke | last post by:
Hello, I have one ImageButton controls which I initialize in Page_Load and declare on class level. ImageButton save = new ImageButton(); save.ImageUrl = "save.gif" save.Click += new...
2
by: Colin Robinson | last post by:
Help please I have an example class called Person with 2 public properties Firstname and Lastname, I cant create a textbox on an asp.net form bound to the Person.Firstname property Can...
1
by: Axel Dahmen | last post by:
Hi, I've added a property to my Page base class (this base class inherits from Page and all my aspx.cs classes inherit from my base class). This property of mine uses the Session object to...
15
by: Mark Goldin | last post by:
I have main aspx page with a number of user controls. How can I create a global property that will be visible in every user control? Thanks
1
by: Dorsa | last post by:
Hi, I'm new to ASP.net and VB.net . I have saved a class ( SecurityClass) that has one property ( LoggedIn ) in the Session Object as SecurityObj. I need to check the property in the...
2
by: Alani | last post by:
Hello All, I'm a new ASP.NET programmer and I want to create a custom control consist of two properties (Number1) and (Number2) and both of them are integers and default value = 0, now I'm...
3
by: velu | last post by:
How to Pass Panel visibility property to other page? I have a scenario here. I have created a user control that has a button and panel visible set to false. When I click the button if the...
3
by: jbeteta | last post by:
Hello, I have a problem declaring variables. I need to create an object oRpte as ReportClass on WebForm1.aspx and be able to use its value on WebForm2.aspx. For declaring the property oRpte()...
13
by: Kirk | last post by:
I have been reading Scott Allen's article on Master Pages (http:// odetocode.com/Articles/450.aspx) but I am having problems understanding a concept. Specifically, I have created a property...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
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...
0
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...

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.