ASP.Net Session programming for Newbie

J

James

Hi there,

I'm just wondering if this is possible in Asp.net - I'm a newbie to Web
Programming:)

I'm building this application that will hold a list Persons. A person can
have First Name, Last Name, Age, Gender etc.
What I want is, whenever a user browser comes onto my ASP.net page for the
very first time, I want a fresh/new list
of my Persons object to be given to the user - this is an Array of Person.
The user will then be able to change the list by deleting a few items from
the list.

The key thing I'm looking for, is when the browser window is closed, I want
ALL changes that were made to the person object/list/array to be discarded.
However,
if the user browser window is NOT closed, then the used may see changes made
to the list of persons. Please note that multiple users may log onto my
site at any given time,
and I want each user to have a Fresh list of persons object in which they
may manipulate.

My question to you all ASP.Net gurus are:

1.) Is this possible with using only objects loaded in memory?
2.) Will I need to use Session objects for this?
3.) What is the most simplistic way to implement such a page?


thanks,
 
M

Michael Nemtsev [MVP]

Hello james,

j> 1.) Is this possible with using only objects loaded in memory?

Yep, just use the Cache class in for this, where u can store your data

j> 2.) Will I need to use Session objects for this?

yep, and you can control your data lifetime by the Session_End event, which
rise when user close browser. Take into account that it works only for the
InProc session mode

---
WBR,
Michael Nemtsev [.NET/C# MVP] :: blog: http://spaces.live.com/laflour

"The greatest danger for most of us is not that our aim is too high and we
miss it, but that it is too low and we reach it" (c) Michelangelo


j> Hi there,
j>
j> I'm just wondering if this is possible in Asp.net - I'm a newbie to
j> Web Programming:)
j>
j> I'm building this application that will hold a list Persons. A person
j> can
j> have First Name, Last Name, Age, Gender etc.
j> What I want is, whenever a user browser comes onto my ASP.net page
j> for the
j> very first time, I want a fresh/new list
j> of my Persons object to be given to the user - this is an Array of
j> Person.
j> The user will then be able to change the list by deleting a few items
j> from
j> the list.
j> The key thing I'm looking for, is when the browser window is closed,
j> I want
j> ALL changes that were made to the person object/list/array to be
j> discarded.
j> However,
j> if the user browser window is NOT closed, then the used may see
j> changes made
j> to the list of persons. Please note that multiple users may log onto
j> my
j> site at any given time,
j> and I want each user to have a Fresh list of persons object in which
j> they
j> may manipulate.
j> My question to you all ASP.Net gurus are:
j>
j> 1.) Is this possible with using only objects loaded in memory?
j> 2.) Will I need to use Session objects for this?
j> 3.) What is the most simplistic way to implement such a page?
j> thanks,
j>
 
A

Anthony Jones

James said:
Hi there,

I'm just wondering if this is possible in Asp.net - I'm a newbie to Web
Programming:)

I'm building this application that will hold a list Persons. A person can
have First Name, Last Name, Age, Gender etc.
What I want is, whenever a user browser comes onto my ASP.net page for the
very first time, I want a fresh/new list
of my Persons object to be given to the user - this is an Array of Person.
The user will then be able to change the list by deleting a few items from
the list.

The key thing I'm looking for, is when the browser window is closed, I want
ALL changes that were made to the person object/list/array to be discarded.
However,
if the user browser window is NOT closed, then the used may see changes made
to the list of persons. Please note that multiple users may log onto my
site at any given time,
and I want each user to have a Fresh list of persons object in which they
may manipulate.

My question to you all ASP.Net gurus are:

1.) Is this possible with using only objects loaded in memory?
Yes

2.) Will I need to use Session objects for this?

Need is a too strong a word. Its one reasonable way in this given scenario.
3.) What is the most simplistic way to implement such a page?

<script runat="server">
Person[] people;

protected void Page_Load(object sender, EventArgs e)
{
people== (Person[])Session["people"];
if (people== null)
{
people== GetInitialPeople();
Session["people"] = people;
}
}
</script>
 
A

Anthony Jones

Michael Nemtsev said:
Hello james,

j> 1.) Is this possible with using only objects loaded in memory?

Yep, just use the Cache class in for this, where u can store your data

j> 2.) Will I need to use Session objects for this?

yep, and you can control your data lifetime by the Session_End event, which
rise when user close browser. Take into account that it works only for the
InProc session mode


How does session know when the user has closed the browser?
What constitutes a 'browser close', when allow windows/tabs currently
showing content from the site are closed or navigated to another site?
 
M

Michael Nemtsev [MVP]

Hello Anthony,

I wasn't clear enough - *shame me* :)

You can't control the Session_End by closing the browser - it doesnt activate
the Session_End at all

I meant that after the session timeout (setting in config) that event will
be called, or if you call Session.Abandon manually.
So, OP should rely either on that timeout or logout explicitly calling Session.Abandon

---
WBR,
Michael Nemtsev [.NET/C# MVP] :: blog: http://spaces.live.com/laflour

"The greatest danger for most of us is not that our aim is too high and we
miss it, but that it is too low and we reach it" (c) Michelangelo


AJ> AJ> AJ> which
AJ> AJ> How does session know when the user has closed the browser?
AJ> What constitutes a 'browser close', when allow windows/tabs
AJ> currently
AJ> showing content from the site are closed or navigated to another
AJ> site
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,982
Messages
2,570,186
Members
46,742
Latest member
AshliMayer

Latest Threads

Top