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

A way to refer to items in Session object without using Session directly

Is there a way to refer to things in Session object without calling Session
itself?

Jun 27 '08 #1
8 1178
Yea,

Just keep it in both places.... Session and other container/place you will
use to get those things...
---------------------------------------------------------------------------
On a serious note..... What are you trying to do.
Will HttpContext.Current.Session help?
you can access Session object from your business logic without passing
Session around....If that is what you trying to avoid.

George.

"Andy B" <a_*****@sbcglobal.netwrote in message
news:%2***************@TK2MSFTNGP06.phx.gbl...
Is there a way to refer to things in Session object without calling
Session itself?

Jun 27 '08 #2
Hi,

if you intend to keep your component loosely coupled, so that it does not
require ASP.NET's session to exist (if you intend to use it in other types
of apps or in a web service etc), you can design so that you have a type in
the component library which represents the data the usual component in that
library needs. E.g create a type to abstract the concept of a session for
your components.

You can instantiate that object (session type) in ASP.NET, store it in
ASP.NEt's Session if needed, but when using components from the library, you
pass it(them) the session object so the component wouldn't need to do grabs
to the ASP.NET Session.

Some background why just HttpContext.Current.Session is a bad thing:
http://aspadvice.com/blogs/joteke/ar.../23/16785.aspx

--
Teemu Keiski
AspInsider, ASP.NET MVP
http://blogs.aspadvice.com/joteke
http://teemukeiski.net

"Andy B" <a_*****@sbcglobal.netwrote in message
news:%2***************@TK2MSFTNGP06.phx.gbl...
Is there a way to refer to things in Session object without calling
Session itself?

Jun 27 '08 #3
I am trying to avoid having to do something like this every time I want an
object from Session:
((DataSet)Session["ContractDataSet"]).Tables["..."]...;
or:
DataSet ContractDataSet = (DataSet)Session["ContractDataSet"];
//...whatever with CongtractDataSet

Session["ContractDataSet"]=ContractDataSet;

I want a way to create and refer to just ContractDataSEt but have it linked
to Session["ContractDataSet"] as well as ContractDataSet. I just need the
code in VB 9.


"George Ter-Saakov" <gt****@cardone.comwrote in message
news:OF**************@TK2MSFTNGP05.phx.gbl...
Yea,

Just keep it in both places.... Session and other container/place you will
use to get those things...
---------------------------------------------------------------------------
On a serious note..... What are you trying to do.
Will HttpContext.Current.Session help?
you can access Session object from your business logic without passing
Session around....If that is what you trying to avoid.

George.

"Andy B" <a_*****@sbcglobal.netwrote in message
news:%2***************@TK2MSFTNGP06.phx.gbl...
>Is there a way to refer to things in Session object without calling
Session itself?


Jun 27 '08 #4
You could make a wrapper class and create a property. The get and set for
the property will then call the session object:

public class MyDataClass
{

public static DataSet ContractDataSet
{
get
{
return (DataSet)Session["ContractDataSet"];
}
set
{
Session["ContractDataSet"] = value;
}
}

}
You might want to do some null checks as well.

Regards,
Rick Davis
DBG Software
"Andy B" wrote:
I am trying to avoid having to do something like this every time I want an
object from Session:
((DataSet)Session["ContractDataSet"]).Tables["..."]...;
or:
DataSet ContractDataSet = (DataSet)Session["ContractDataSet"];
//...whatever with CongtractDataSet

Session["ContractDataSet"]=ContractDataSet;

I want a way to create and refer to just ContractDataSEt but have it linked
to Session["ContractDataSet"] as well as ContractDataSet. I just need the
code in VB 9.


"George Ter-Saakov" <gt****@cardone.comwrote in message
news:OF**************@TK2MSFTNGP05.phx.gbl...
Yea,

Just keep it in both places.... Session and other container/place you will
use to get those things...
---------------------------------------------------------------------------
On a serious note..... What are you trying to do.
Will HttpContext.Current.Session help?
you can access Session object from your business logic without passing
Session around....If that is what you trying to avoid.

George.

"Andy B" <a_*****@sbcglobal.netwrote in message
news:%2***************@TK2MSFTNGP06.phx.gbl...
Is there a way to refer to things in Session object without calling
Session itself?


Jun 27 '08 #5
So this would be a static class that is maintained outside the bounds of the
page that uses it then? And I would probably put other methods/events in
this class that use the same session object?
"dbgrick" <db*****@discussions.microsoft.comwrote in message
news:1B**********************************@microsof t.com...
You could make a wrapper class and create a property. The get and set for
the property will then call the session object:

public class MyDataClass
{

public static DataSet ContractDataSet
{
get
{
return (DataSet)Session["ContractDataSet"];
}
set
{
Session["ContractDataSet"] = value;
}
}

}
You might want to do some null checks as well.

Regards,
Rick Davis
DBG Software
"Andy B" wrote:
>I am trying to avoid having to do something like this every time I want
an
object from Session:
((DataSet)Session["ContractDataSet"]).Tables["..."]...;
or:
DataSet ContractDataSet = (DataSet)Session["ContractDataSet"];
//...whatever with CongtractDataSet

Session["ContractDataSet"]=ContractDataSet;

I want a way to create and refer to just ContractDataSEt but have it
linked
to Session["ContractDataSet"] as well as ContractDataSet. I just need the
code in VB 9.


"George Ter-Saakov" <gt****@cardone.comwrote in message
news:OF**************@TK2MSFTNGP05.phx.gbl...
Yea,

Just keep it in both places.... Session and other container/place you
will
use to get those things...
---------------------------------------------------------------------------
On a serious note..... What are you trying to do.
Will HttpContext.Current.Session help?
you can access Session object from your business logic without passing
Session around....If that is what you trying to avoid.

George.

"Andy B" <a_*****@sbcglobal.netwrote in message
news:%2***************@TK2MSFTNGP06.phx.gbl...
Is there a way to refer to things in Session object without calling
Session itself?





Jun 27 '08 #6
"dbgrick" <db*****@discussions.microsoft.comwrote in message
news:1B**********************************@microsof t.com...
You could make a wrapper class and create a property.
That will not prevent the Session object from actually being called, albeit
behind the scenes - all it will do is create a completely unnecessary
additional layer of code for no benefit whatsoever...

If you want to use the Session cache, then you need to refer to it - no
getting round that...
--
Mark Rae
ASP.NET MVP
http://www.markrae.net

Jun 27 '08 #7
If all it was used for was to wrap around the Session, then it would be kind
of useless. Since the design and code of the wizard I am working on deals
with a lot of transactions between datasets and the frontend, I will need to
create other methods and properties to get the work done. Insdead of making
tons of senseless clutter inside the page, I can just make it inside a class
and then reference the class in the page code behind. Unless of course, that
isn't a good idea...
"Mark Rae [MVP]" <ma**@markNOSPAMrae.netwrote in message
news:Ok**************@TK2MSFTNGP02.phx.gbl...
"dbgrick" <db*****@discussions.microsoft.comwrote in message
news:1B**********************************@microsof t.com...
>You could make a wrapper class and create a property.

That will not prevent the Session object from actually being called,
albeit behind the scenes - all it will do is create a completely
unnecessary additional layer of code for no benefit whatsoever...

If you want to use the Session cache, then you need to refer to it - no
getting round that...
--
Mark Rae
ASP.NET MVP
http://www.markrae.net

Jun 27 '08 #8
On May 29, 11:12*pm, "Mark Rae [MVP]" <m...@markNOSPAMrae.netwrote:
"dbgrick" <dbgr...@discussions.microsoft.comwrote in message

news:1B**********************************@microsof t.com...
You could make a wrapper class and create a property.

That will not prevent the Session object from actually being called, albeit
behind the scenes - all it will do is create a completely unnecessary
additional layer of code for no benefit whatsoever...

If you want to use the Session cache, then you need to refer to it - no
getting round that...
It ensures a) that there's no typos anywhere where the same object is
being accessed, and b) that there's agreement at all points of access
on what the data type is. (a) could be achieved by introducing a
constant, but (b) could only be achieved in that case by searching the
codebase. It's a lot nicer if you're changing a datatype to do it
inside this wrapper class and then have the compiler tell you of any
problems with that.

Damien
Jun 27 '08 #9

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

Similar topics

11
by: Stephen | last post by:
I was wondering if someone can help me with an web application design problem. I have a aspx page which builds up an arraylist called addresses and outputs the values in the arraylist items to a...
4
by: theo | last post by:
Program flow...load file,then extract the xml text tags from the file,then the number of Xml tags retrieved from the file determines the number of dropdownlist controls instanciated in the...
6
by: Vik | last post by:
A dataset is saved in session state. Then the dataset is filled out with the new records using a dataadapter. It appears then that the dataset saved in session state contains the new records even...
7
by: Keith Patrick | last post by:
After completely giving up on finding some way in my ASP.Net app to take a query string URL and redirect to it as a POST instead, I went with a system like so: Upon "redirection," all the...
1
by: sneha123 | last post by:
There will be some 20 questions and for each question there will be 4 choices.what i want to do is to select multiple answers by clicking the checkbox. i m using asp.net,vb.net pls help me we...
13
by: | last post by:
Simple question, I think... I'm storing an object in the Session object. In the code behind I read that object: trx = CType(Session("Transaction"), BOCSTransaction) If I change any...
6
by: Kermit Piper | last post by:
Hello, I thought this should be easy, but... all I want to do is set the value of this state drop-down based on a session var I'm getting back from a redirect (from the processing page): <%...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.