473,385 Members | 1,712 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,385 software developers and data experts.

Best Practices - User Data & Sessions?

Hello,

I am hoping to get some guidance on the following scenerio:

I have a password protected site where users have various
permissions. Are sessions the best way of storing the user's id? And
if so, on load of a page should I be hitting the database for their
permissions (based on the session stored user id), or should
everything I need be stored in session variables to save the trip to
the database? I have also wondered about serializing the user object
and sending it from page to page, but I have no idea as to what the
'official' or 'best' practice is for maintaining this kind of data
from page to page.

Any help would be greatly appreciated.

Sep 13 '07 #1
3 4003
<at*********@hotmail.comwrote in message
news:11**********************@y42g2000hsy.googlegr oups.com...
I am hoping to get some guidance on the following scenerio:

I have a password protected site where users have various
permissions. Are sessions the best way of storing the user's id? And
if so, on load of a page should I be hitting the database for their
permissions (based on the session stored user id), or should
everything I need be stored in session variables to save the trip to
the database? I have also wondered about serializing the user object
and sending it from page to page, but I have no idea as to what the
'official' or 'best' practice is for maintaining this kind of data
from page to page.

Any help would be greatly appreciated.
I don't think there is any sort of 'best practice' guidelines for this, so
here's what I usually do...

Application object
Use for high-level lookup data which will change only very infrequently,
e.g. country codes, currency codes, public holidays etc. However, this is
really only sensible if the data will be used very frequently by a
significant number of pages within the web app. E.g. if you have a web app
with 200 pages and only one or two of those need to refer to public
holidays, there's little point in caching the data in the Application
object.

Session object
Use for lookup data which is highly unlikely to change throughout the
duration of a session and which is used by many pages. As you mention,
metadata about the currently logged-on user is usually a good candidate for
storage in the Session object. However, I *never* pass Session data between
pages - there's no point at all, as Session is available to all pages
anyway...

Try not to use the SessionID for any sort of reference, as it's not 100%
guaranteed to be unique across all scenarios. There should be no need to use
the SessionID for anything anyway, as it's not meaningful data. E.g my
current SessionID is "X" but yesterday it was "Y" - so what... :-)

Also, bear in mind that when you use inproc sessions, every piece of data
you store in the Session object eats away at the total amount of memory...
Obviously, modern webservers tend to have bags of memory anyway, but it's
still something to consider... I've seen installations where the webserver
had 512Mb RAM, and each user's Session was over 1Mb big - a few hundred
concurrent users and the thing will grind to a halt very quickly...

Finally, if you use SQL Server to persist your Session objects, the above is
slightly irrelevant as you'll be hitting the database no matter what you
do... This again needs a bit of planning because e.g. Session_End doesn't
fire if you're not using inproc sessions...
--
Mark Rae
ASP.NET MVP
http://www.markrae.net

Sep 13 '07 #2

Thank You! This is exactly what I was looking for :)

On Sep 13, 4:51 pm, "Mark Rae [MVP]" <m...@markNOSPAMrae.netwrote:
<at_the_g...@hotmail.comwrote in message

news:11**********************@y42g2000hsy.googlegr oups.com...
I am hoping to get some guidance on the following scenerio:
I have a password protected site where users have various
permissions. Are sessions the best way of storing the user's id? And
if so, on load of a page should I be hitting the database for their
permissions (based on the session stored user id), or should
everything I need be stored in session variables to save the trip to
the database? I have also wondered about serializing the user object
and sending it from page to page, but I have no idea as to what the
'official' or 'best' practice is for maintaining this kind of data
from page to page.
Any help would be greatly appreciated.

I don't think there is any sort of 'best practice' guidelines for this, so
here's what I usually do...

Application object
Use for high-level lookup data which will change only very infrequently,
e.g. country codes, currency codes, public holidays etc. However, this is
really only sensible if the data will be used very frequently by a
significant number of pages within the web app. E.g. if you have a web app
with 200 pages and only one or two of those need to refer to public
holidays, there's little point in caching the data in the Application
object.

Session object
Use for lookup data which is highly unlikely to change throughout the
duration of a session and which is used by many pages. As you mention,
metadata about the currently logged-on user is usually a good candidate for
storage in the Session object. However, I *never* pass Session data between
pages - there's no point at all, as Session is available to all pages
anyway...

Try not to use the SessionID for any sort of reference, as it's not 100%
guaranteed to be unique across all scenarios. There should be no need to use
the SessionID for anything anyway, as it's not meaningful data. E.g my
current SessionID is "X" but yesterday it was "Y" - so what... :-)

Also, bear in mind that when you use inproc sessions, every piece of data
you store in the Session object eats away at the total amount of memory...
Obviously, modern webservers tend to have bags of memory anyway, but it's
still something to consider... I've seen installations where the webserver
had 512Mb RAM, and each user's Session was over 1Mb big - a few hundred
concurrent users and the thing will grind to a halt very quickly...

Finally, if you use SQL Server to persist your Session objects, the above is
slightly irrelevant as you'll be hitting the database no matter what you
do... This again needs a bit of planning because e.g. Session_End doesn't
fire if you're not using inproc sessions...

--
Mark Rae
ASP.NET MVPhttp://www.markrae.net

Sep 14 '07 #3
On Thu, 13 Sep 2007 13:30:57 -0700, at*********@hotmail.com wrote:
>Hello,

I am hoping to get some guidance on the following scenerio:

I have a password protected site where users have various
permissions. Are sessions the best way of storing the user's id?
Are you using forms authentification? I rely on the UserData property of
the FormsAuthentificationTicket; and I rewrite the tickets (to the
cookie) at the start of each new session; after having confirmed the
user roles from the database (at the start of the session - in the
AuthenticateRequest event.)
>And if so, on load of a page should I be hitting the database for their
permissions (based on the session stored user id), or should
everything I need be stored in session variables to save the trip to
the database?
You only need to hit the database for user information at the start of a
session; but there is a SqlRoleProvider, should you want it.
>I have also wondered about serializing the user object
and sending it from page to page, but I have no idea as to what the
'official' or 'best' practice is for maintaining this kind of data
from page to page.

Any help would be greatly appreciated.
You probably don't need to specifically serialize any user objects. But
you can have custom user objects if you want and these can then be
managed as per the default.

Lookup "Role Manager", IPrincipal, RolePrincipal class, GenericPrincipal
and AuthenticateRequest.

<http://www.codeproject.com/aspnet/formsroleauth.asp>

<http://www.codeproject.com/aspnet/aspnet2security.asp>

Stefan Schackow has an entire book available called "Professional
ASP.NET 2.0 Security, Membership, and Role Management"; which is an
amazing 608 pages! Hard to figure why it needed to be so large; but it
is pretty comprehensive; but not incredibly practical from a cook-book
point of view. It's hard to recommend this book; the index is not very
good and what use is a reference book without a very good index?
Sep 17 '07 #4

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

Similar topics

15
by: Joshua Beall | last post by:
Hi All, What is the best way to use a cookie to remember a logged in user? Would you store the username and password in two separate cookies? Should the password be plain text? Hashed? Not...
2
by: d.schulz81 | last post by:
Hi all, We have about 10 different domains that are linked very closely and we want to identify and track every single user that surfs our websites. Later we want to analyse user paths and find...
11
by: DrUg13 | last post by:
In java, this seems so easy. You need a new object Object test = new Object() gives me exactly what I want. could someone please help me understand the different ways to do the same thing in...
8
by: Ian Davies | last post by:
Hello I am trying to run a few INSERT queries only if the user clicks 'continue' in a <a href> The queries takes variables created from SELECT queries. I have tried to acheive this by putting The...
0
by: Anonieko Ramos | last post by:
ASP.NET Forms Authentication Best Practices Dr. Dobb's Journal February 2004 Protecting user information is critical By Douglas Reilly Douglas is the author of Designing Microsoft ASP.NET...
1
by: Don | last post by:
When we redirect a user to a new page, we generally want the processing of the current page to end right then. As I understand it, the runtime accomplishes this by generating a ThreadAbort...
1
by: Kevin Frey | last post by:
I've been spending considerable time thinking about the various implications that come into play when building a production-quality web application and this has prompted me to ask whether there are...
7
by: Gladen Blackshield | last post by:
Hello All! Still very new to PHP and I was wondering about the easiest and simplest way to go about doing something for a project I am working on. I would simply like advice on what I'm asking...
41
by: Jim | last post by:
Hi guys, I have an object which represents an "item" in a CMS "component" where an "item" in the most basic form just a field, and a "component" is effectively a table. "item" objects can be...
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: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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.