473,597 Members | 2,113 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 1192
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.Cur rent.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_*****@sbcglo bal.netwrote in message
news:%2******** *******@TK2MSFT NGP06.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.Cur rent.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_*****@sbcglo bal.netwrote in message
news:%2******** *******@TK2MSFT NGP06.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)Sessi on["ContractDataSe t"]).Tables["..."]...;
or:
DataSet ContractDataSet = (DataSet)Sessio n["ContractDataSe t"];
//...whatever with CongtractDataSe t

Session["ContractDataSe t"]=ContractDataSe t;

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


"George Ter-Saakov" <gt****@cardone .comwrote in message
news:OF******** ******@TK2MSFTN GP05.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.Cur rent.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_*****@sbcglo bal.netwrote in message
news:%2******** *******@TK2MSFT NGP06.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)Sessio n["ContractDataSe t"];
}
set
{
Session["ContractDataSe t"] = 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)Sessi on["ContractDataSe t"]).Tables["..."]...;
or:
DataSet ContractDataSet = (DataSet)Sessio n["ContractDataSe t"];
//...whatever with CongtractDataSe t

Session["ContractDataSe t"]=ContractDataSe t;

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


"George Ter-Saakov" <gt****@cardone .comwrote in message
news:OF******** ******@TK2MSFTN GP05.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.Cur rent.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_*****@sbcglo bal.netwrote in message
news:%2******** *******@TK2MSFT NGP06.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*****@discus sions.microsoft .comwrote in message
news:1B******** *************** ***********@mic rosoft.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)Sessio n["ContractDataSe t"];
}
set
{
Session["ContractDataSe t"] = 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)Sess ion["ContractDataSe t"]).Tables["..."]...;
or:
DataSet ContractDataSet = (DataSet)Sessio n["ContractDataSe t"];
//...whatever with CongtractDataSe t

Session["ContractDataSe t"]=ContractDataSe t;

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


"George Ter-Saakov" <gt****@cardone .comwrote in message
news:OF******* *******@TK2MSFT NGP05.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.Cur rent.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_*****@sbcglo bal.netwrote in message
news:%2******** *******@TK2MSFT NGP06.phx.gbl.. .
Is there a way to refer to things in Session object without calling
Session itself?





Jun 27 '08 #6
"dbgrick" <db*****@discus sions.microsoft .comwrote in message
news:1B******** *************** ***********@mic rosoft.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**@markNOSPA Mrae.netwrote in message
news:Ok******** ******@TK2MSFTN GP02.phx.gbl...
"dbgrick" <db*****@discus sions.microsoft .comwrote in message
news:1B******** *************** ***********@mic rosoft.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...@markNOSPA Mrae.netwrote:
"dbgrick" <dbgr...@discus sions.microsoft .comwrote in message

news:1B******** *************** ***********@mic rosoft.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
2161
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 datagrid. I am using the viewstate object to store the Arraylist items on the page on postback. My PROBLEM is that I need to redirect the user to a new aspx page and on this new page i need to be able to access the items in my arraylist. Is this...
4
7447
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 placeholder,the user selects the required tags from the dropdownlists (if 5 Xml tags,then 5 dropdownlists each containing 5 xml tags) and now the btnSave button is selected which extracts the user selection form the dropdownlists.
6
5118
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 without saving the updated dataset. Why does this happen? How can I preserve the dataset saved in session state from automatical updating? Thank you.
7
2724
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 QueryString pairs are placed in HttpContext.Current.Items and retrieved with a wrapper for Request.Params that includes checks there. This works in general instances, but one problem has come up that has me stuck: since the stuff is in the context and...
1
2910
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 have written the code using radio button for selecting single item.but we want to replace it with checkbox to select multiple items. the code using radio button is given below .pls correct it with checkbox
13
1744
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 properties, I have to store it back into the session object to "update" it, right? Or will the changes to my object automatically be saved back into the session object? Thanks, Jerry
6
2430
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): <% tax = session("Tax") city = session("City") state = session("State") %>
0
7969
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
8272
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
8381
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
8035
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
8258
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
3886
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...
0
3927
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2404
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
0
1238
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.