Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / General / March 2008

Tip: Looking for answers? Try searching our database.

ASP.Net Session programming for Newbie

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
James - 02 Mar 2008 09:09 GMT
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,
Michael Nemtsev [MVP] - 02 Mar 2008 13:10 GMT
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>
Anthony Jones - 02 Mar 2008 22:01 GMT
> Hello james,
>
[quoted text clipped - 7 lines]
> 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?

Signature

Anthony Jones - MVP ASP/ASP.NET

Michael Nemtsev [MVP] - 03 Mar 2008 00:03 GMT
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> "Michael Nemtsev [MVP]" <nemtsev@msn.com> wrote in message
AJ> news:900895ec2f15f8ca4ada0e9a3f04@msnews.microsoft.com...
AJ>
>> Hello james,
>>
[quoted text clipped - 6 lines]
>>
>> yep, and you can control your data lifetime by the Session_End event,

AJ> which
AJ>
>> rise when user close browser. Take into account that it works only
>> for the InProc session mode

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
Anthony Jones - 02 Mar 2008 21:58 GMT
> Hi there,
>
[quoted text clipped - 21 lines]
>
> 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>

Signature

Anthony Jones - MVP ASP/ASP.NET


Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.