473,779 Members | 2,041 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

User & application-state variables...

I am relativly new to ASP.NET, and my question is this:

Is it better to create a wrapper class that contains all the running
settings for the application and then load that into the app state, or is it
better to load the scalar variables and store them individually?

In case I'm not making my self clear, is it better to do this:

'// Load each variable individually
Context.Cache.A dd( "UserFirstName" , txtFirstName.Te xt ... )
Context.Cache.A dd( "UserLastNa me", txtLastName.Tex t ... )

or this:

'// Store vars in a class, and then cache the class
Config.ActiveUs er.FirstName = txtFirstName.Te xt
Config.ActiveUs er.LastName = txtLastName.Tex t

Context.Cache.A dd( "Config", Config ... )

?

Thanks,
Jeremy
Nov 18 '05 #1
3 1576
Both ways are valid. It's all about tradeoffs.
The first way is simpler, the second way allows for more custom
functionality.
Simplicity vs. Power is the kind of decision we developers face nearly every
day.
You must decide which way is best for your app.

--
I hope this helps,
Steve C. Orr, MCSD, MVP
http://Steve.Orr.net
"Jeremy" <th***********@ hotmail.com> wrote in message
news:tF******** ************@tw ister.tampabay. rr.com...
I am relativly new to ASP.NET, and my question is this:

Is it better to create a wrapper class that contains all the running
settings for the application and then load that into the app state, or is it better to load the scalar variables and store them individually?

In case I'm not making my self clear, is it better to do this:

'// Load each variable individually
Context.Cache.A dd( "UserFirstName" , txtFirstName.Te xt ... )
Context.Cache.A dd( "UserLastNa me", txtLastName.Tex t ... )

or this:

'// Store vars in a class, and then cache the class
Config.ActiveUs er.FirstName = txtFirstName.Te xt
Config.ActiveUs er.LastName = txtLastName.Tex t

Context.Cache.A dd( "Config", Config ... )

?

Thanks,
Jeremy

Nov 18 '05 #2
Hello Jeremy,
Is it better to create a wrapper class that contains all the running
settings for the application and then load that into the app state, or
is it better to load the scalar variables and store them individually?


My answer is going to be geared toward session, however, I think that you'll be able to apply this anywhere.

Typically, the first thing that I do when I start up a web project that requires session state is implement a wrapper class for it that looks like this:

class SessionManager
{
private const string SESSION_MANAGER = "SESSION_MANAGE R";
private string username;

private SessionManager( )
{
}

public string UserName
{
get { return username; }
set { username = value; }
}

public static SessionManager Instance
{
SessionManager manager = HttpContext.Cur rent.Session[SESSION_MANAGER] as SessionManager;
if (manager == null)
{
manager = new SessionManager( );
HttpContext.Cur rent.Session[SESSION_MANAGER] = manager;
}
return manager;
}
}

Using this class is very simple. All you need to do is add property accessors to it for items that you wish to store in session, as I have done in the above example with the UserName property.

When I want to access the session state in the code, I type
SessionManager. Instance.UserNa me = "someValue" ; or
string someValue = SessionManager. Instance.UserNa me;

What I have now is a singleton pattern that exposes any session state that I need in a strongly typed fashion (ie: no longer do I run the risk of accidentally typing in the wrong string when I do Session["someValue"]). I can also control whether or not a property is read only at compile time.

I hope this answers your question.

--
Matt Berther
<a href="http://www.mattberther .com">http://www.mattberther .com</a>

Nov 18 '05 #3
As another follow up -

Be careful not to put user specific information (like first and last
name) into the cache without some unique per user identifier (or
consider using the Session object). Otherwise two different users may
see the same name pulled from the cache when they come to your site.

--
Scott
http://www.OdeToCode.com

On Thu, 15 Apr 2004 15:27:29 -0700, "Steve C. Orr [MVP, MCSD]"
<St***@Orr.ne t> wrote:
Both ways are valid. It's all about tradeoffs.
The first way is simpler, the second way allows for more custom
functionalit y.
Simplicity vs. Power is the kind of decision we developers face nearly every
day.
You must decide which way is best for your app.


Nov 18 '05 #4

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

Similar topics

4
2814
by: MLH | last post by:
A programmer developed an AMP (Apache/MySQL/PHP) application for me. When he was done, he sent me the PHP files and the MySQL dump file. Now, when I connect to the application on my LAN using http://192.168.1.106/~mlh/credifree/index.php the AMP app still thinks the data resides somewhere else. It runs fine - as long as I leave my LAN's external internet connection up. But if I unplug my LAN from the world, my app locks up. Before I...
88
12558
by: Mike | last post by:
Is there a way to determine what a user's default email client is? I read a post from 3 years ago that said no. I guess I'm hoping something has come along since then.
4
3229
by: johkar | last post by:
When the output method is set to xml, even though I have CDATA around my JavaScript, the operaters of && and < are converted to XML character entities which causes errors in my JavaScript. I know that I could externalize my JavaScript, but that will not be practical throughout this application. Is there any way to get around this issue? Xalan processor. Stripped down stylesheet below along with XHTML output. <?xml version='1.0'?>...
1
356
by: Nathan Alden | last post by:
I have an XSD defined as the following: <?xml version="1.0" encoding="UTF-8"?> <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" attributeFormDefault="unqualified"> <xs:element name="Application"> <xs:complexType> <xs:sequence> <xs:element name="ReceivedDate" type="xs:string"/> </xs:sequence>
4
2114
by: Jason Shohet | last post by:
A user runs a .NET application that authenticates them against active directory (they're coming in over VPN so they don't log on to the network normally). Once they log in, I want to take their user id, & run a batch file on their PC with that user id actually inside the batch file. (The objective here is to map a user to a drive on the network when they come in thru VPN -- and that can only be done with a batch file we have, customized...
2
1372
by: memHog | last post by:
I am trying to create a windows application that will perform drag and drop between a usercontrol on a toolbar and a "user document". As the user control is being dragged accross the user document, I would like the image of the user document to be displayed. The behavior of the dragged item needs to be not unlike that of the cards in solitare. I can do the standard drag & drop stuff but don't know how to change the dragged items shape...
2
2424
by: Patrick Blackman | last post by:
Hi, need some info on implementing a multiuser winforms application, specifically managing user logins and user preferences & access rights. Are there any frameworks out there for this. I don't want to use windows identity system. Any pointers would be appreciated.
0
1316
by: WhiteWizard | last post by:
Here’s the situation: I am writing a C# Windows application using VS 2003. I have built a user control, and it has a Tab Control on it with (currently) 2 tab pages, and the whole thing sits on a panel (for resizing with a splitter etc). Each of the tab pages is marked AutoScroll = true. When I load the application I load a tree-view control (scrollable = false), to the first tab page, and that page has system scroll bars that...
0
1147
by: sreehari | last post by:
Hi, I have a problem and dont have much clue on how to proceed with it. il try to describe the situation best below. I have a user control, and two forms which i have exported as template items. Now the user control, when clicked should be able to display one of the template forms. the problem is if i know this before hand, i can implement the code for this in the click event of the usr control itself and then release to the client....
2
1433
by: =?Utf-8?B?VW1lc2huYXRo?= | last post by:
Hi, My application is running with two web server let say W1 & W2 and load balance controls the request to web servers . One of my application page pop up a new page and there I am using Context.User prpoerty to get current user informtaion and convert into my customer class which lot of customer information . This works fine in Developement environment and when it moves to production some times the customer class is not getting...
0
9636
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10306
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
10138
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
10074
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
8961
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7485
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
5373
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
4037
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
2
3632
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.