Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Access SessionState in Business Tier

Reply
Thread Tools

Access SessionState in Business Tier

 
 
Glenn
Guest
Posts: n/a
 
      01-06-2004
Hi,

I know that I can access session state on an asp.net page
using either HttpContext or Page objects, but how do I
access session data from middle tiers?

Should the technique be to extricate the necessary session
data with a web page and pass this to the business tier?

If I need to alter session state in a middle tier object,
should I use a reference parameter and update the session
state when the method call is complete?

Thanks,

Glenn.
 
Reply With Quote
 
 
 
 
Steve C. Orr [MVP, MCSD]
Guest
Posts: n/a
 
      01-06-2004
You could just use the HttpContext object from your business tier.
Or if you want your business objects to be more generic so they could be
used from other (non-web) front ends in the future then you may just want to
only pass value types as parameters to your business objects. In this case
your page objects would extract the necessary information from session state
so the business objects don't need to deal with any web stuff.

--
I hope this helps,
Steve C. Orr, MCSD, MVP
http://Steve.Orr.net
Hire top-notch developers at http://www.able-consulting.com



"Glenn" <> wrote in message
news:036c01c3d4aa$6f2db0a0$...
> Hi,
>
> I know that I can access session state on an asp.net page
> using either HttpContext or Page objects, but how do I
> access session data from middle tiers?
>
> Should the technique be to extricate the necessary session
> data with a web page and pass this to the business tier?
>
> If I need to alter session state in a middle tier object,
> should I use a reference parameter and update the session
> state when the method call is complete?
>
> Thanks,
>
> Glenn.



 
Reply With Quote
 
 
 
 
Glenn
Guest
Posts: n/a
 
      01-06-2004
My initial thoughts were that the HTTPContext object would
not be in scope in a middle tier object method, hence
passing individual session values as method parameters. Is
this correct?

Here is a subset of the sample I knocked up to test this
scenario:

public string GetTypes()
{
using System.Web;
StringBuilder sb = new StringBuilder();
sb.Append(HttpContext.Session["UserID"].ToString());
return(sb.ToString());
}

The following message is generated:

An object reference is required for the nonstatic field,
method, or property 'System.Web.HttpContext.Session'.

Do I need to pass the HTTPContext object to the middle
tier object through a method parameter?

>-----Original Message-----
>You could just use the HttpContext object from your

business tier.
>Or if you want your business objects to be more generic

so they could be
>used from other (non-web) front ends in the future then

you may just want to
>only pass value types as parameters to your business

objects. In this case
>your page objects would extract the necessary information

from session state
>so the business objects don't need to deal with any web

stuff.
>
>--
>I hope this helps,
>Steve C. Orr, MCSD, MVP
>http://Steve.Orr.net
>Hire top-notch developers at http://www.able-

consulting.com
>
>
>
>"Glenn" <> wrote in

message
>news:036c01c3d4aa$6f2db0a0$...
>> Hi,
>>
>> I know that I can access session state on an asp.net

page
>> using either HttpContext or Page objects, but how do I
>> access session data from middle tiers?
>>
>> Should the technique be to extricate the necessary

session
>> data with a web page and pass this to the business tier?
>>
>> If I need to alter session state in a middle tier

object,
>> should I use a reference parameter and update the

session
>> state when the method call is complete?
>>
>> Thanks,
>>
>> Glenn.

>
>
>.
>

 
Reply With Quote
 
Hermit Dave
Guest
Posts: n/a
 
      01-06-2004
yes it would not be in the scope of middle tier... but you can always have a
member function of middle tier taking in Context object as a ref param and
same applies with Session.
if you dont want to make any modifications... you could try passing it a
clone...

--
Regards,

HD

"Glenn" <> wrote in message
news:03f701c3d4b0$17b24ec0$...
> My initial thoughts were that the HTTPContext object would
> not be in scope in a middle tier object method, hence
> passing individual session values as method parameters. Is
> this correct?
>
> Here is a subset of the sample I knocked up to test this
> scenario:
>
> public string GetTypes()
> {
> using System.Web;
> StringBuilder sb = new StringBuilder();
> sb.Append(HttpContext.Session["UserID"].ToString());
> return(sb.ToString());
> }
>
> The following message is generated:
>
> An object reference is required for the nonstatic field,
> method, or property 'System.Web.HttpContext.Session'.
>
> Do I need to pass the HTTPContext object to the middle
> tier object through a method parameter?
>
> >-----Original Message-----
> >You could just use the HttpContext object from your

> business tier.
> >Or if you want your business objects to be more generic

> so they could be
> >used from other (non-web) front ends in the future then

> you may just want to
> >only pass value types as parameters to your business

> objects. In this case
> >your page objects would extract the necessary information

> from session state
> >so the business objects don't need to deal with any web

> stuff.
> >
> >--
> >I hope this helps,
> >Steve C. Orr, MCSD, MVP
> >http://Steve.Orr.net
> >Hire top-notch developers at http://www.able-

> consulting.com
> >
> >
> >
> >"Glenn" <> wrote in

> message
> >news:036c01c3d4aa$6f2db0a0$...
> >> Hi,
> >>
> >> I know that I can access session state on an asp.net

> page
> >> using either HttpContext or Page objects, but how do I
> >> access session data from middle tiers?
> >>
> >> Should the technique be to extricate the necessary

> session
> >> data with a web page and pass this to the business tier?
> >>
> >> If I need to alter session state in a middle tier

> object,
> >> should I use a reference parameter and update the

> session
> >> state when the method call is complete?
> >>
> >> Thanks,
> >>
> >> Glenn.

> >
> >
> >.
> >



 
Reply With Quote
 
Steve C. Orr [MVP, MCSD]
Guest
Posts: n/a
 
      01-07-2004
You have the wrong syntax.
Instead, use System.Web.HttpContext.Current.Session

--
I hope this helps,
Steve C. Orr, MCSD, MVP
http://Steve.Orr.net
Hire top-notch developers at http://www.able-consulting.com




"Glenn" <> wrote in message
news:03f701c3d4b0$17b24ec0$...
> My initial thoughts were that the HTTPContext object would
> not be in scope in a middle tier object method, hence
> passing individual session values as method parameters. Is
> this correct?
>
> Here is a subset of the sample I knocked up to test this
> scenario:
>
> public string GetTypes()
> {
> using System.Web;
> StringBuilder sb = new StringBuilder();
> sb.Append(HttpContext.Session["UserID"].ToString());
> return(sb.ToString());
> }
>
> The following message is generated:
>
> An object reference is required for the nonstatic field,
> method, or property 'System.Web.HttpContext.Session'.
>
> Do I need to pass the HTTPContext object to the middle
> tier object through a method parameter?
>
> >-----Original Message-----
> >You could just use the HttpContext object from your

> business tier.
> >Or if you want your business objects to be more generic

> so they could be
> >used from other (non-web) front ends in the future then

> you may just want to
> >only pass value types as parameters to your business

> objects. In this case
> >your page objects would extract the necessary information

> from session state
> >so the business objects don't need to deal with any web

> stuff.
> >
> >--
> >I hope this helps,
> >Steve C. Orr, MCSD, MVP
> >http://Steve.Orr.net
> >Hire top-notch developers at http://www.able-

> consulting.com
> >
> >
> >
> >"Glenn" <> wrote in

> message
> >news:036c01c3d4aa$6f2db0a0$...
> >> Hi,
> >>
> >> I know that I can access session state on an asp.net

> page
> >> using either HttpContext or Page objects, but how do I
> >> access session data from middle tiers?
> >>
> >> Should the technique be to extricate the necessary

> session
> >> data with a web page and pass this to the business tier?
> >>
> >> If I need to alter session state in a middle tier

> object,
> >> should I use a reference parameter and update the

> session
> >> state when the method call is complete?
> >>
> >> Thanks,
> >>
> >> Glenn.

> >
> >
> >.
> >



 
Reply With Quote
 
Glenn
Guest
Posts: n/a
 
      01-07-2004
Is this technique commonly used? To the inexperienced eye
it seems fairly expensive...
>-----Original Message-----
>yes it would not be in the scope of middle tier... but

you can always have a
>member function of middle tier taking in Context object

as a ref param and
>same applies with Session.
>if you dont want to make any modifications... you could

try passing it a
>clone...
>
>--
>Regards,
>
>HD
>
>"Glenn" <> wrote in

message
>news:03f701c3d4b0$17b24ec0$...
>> My initial thoughts were that the HTTPContext object

would
>> not be in scope in a middle tier object method, hence
>> passing individual session values as method parameters.

Is
>> this correct?
>>
>> Here is a subset of the sample I knocked up to test this
>> scenario:
>>
>> public string GetTypes()
>> {
>> using System.Web;
>> StringBuilder sb = new StringBuilder();
>> sb.Append(HttpContext.Session["UserID"].ToString());
>> return(sb.ToString());
>> }
>>
>> The following message is generated:
>>
>> An object reference is required for the nonstatic field,
>> method, or property 'System.Web.HttpContext.Session'.
>>
>> Do I need to pass the HTTPContext object to the middle
>> tier object through a method parameter?
>>
>> >-----Original Message-----
>> >You could just use the HttpContext object from your

>> business tier.
>> >Or if you want your business objects to be more generic

>> so they could be
>> >used from other (non-web) front ends in the future then

>> you may just want to
>> >only pass value types as parameters to your business

>> objects. In this case
>> >your page objects would extract the necessary

information
>> from session state
>> >so the business objects don't need to deal with any web

>> stuff.
>> >
>> >--
>> >I hope this helps,
>> >Steve C. Orr, MCSD, MVP
>> >http://Steve.Orr.net
>> >Hire top-notch developers at http://www.able-

>> consulting.com
>> >
>> >
>> >
>> >"Glenn" <> wrote in

>> message
>> >news:036c01c3d4aa$6f2db0a0$...
>> >> Hi,
>> >>
>> >> I know that I can access session state on an asp.net

>> page
>> >> using either HttpContext or Page objects, but how do

I
>> >> access session data from middle tiers?
>> >>
>> >> Should the technique be to extricate the necessary

>> session
>> >> data with a web page and pass this to the business

tier?
>> >>
>> >> If I need to alter session state in a middle tier

>> object,
>> >> should I use a reference parameter and update the

>> session
>> >> state when the method call is complete?
>> >>
>> >> Thanks,
>> >>
>> >> Glenn.
>> >
>> >
>> >.
>> >

>
>
>.
>

 
Reply With Quote
 
Glenn
Guest
Posts: n/a
 
      01-07-2004
Thanks for your help, works well now without having to
pass any parameters around... much appreciated.

>-----Original Message-----
>You have the wrong syntax.
>Instead, use System.Web.HttpContext.Current.Session
>
>--
>I hope this helps,
>Steve C. Orr, MCSD, MVP
>http://Steve.Orr.net
>Hire top-notch developers at http://www.able-

consulting.com
>
>
>
>
>"Glenn" <> wrote in

message
>news:03f701c3d4b0$17b24ec0$...
>> My initial thoughts were that the HTTPContext object

would
>> not be in scope in a middle tier object method, hence
>> passing individual session values as method parameters.

Is
>> this correct?
>>
>> Here is a subset of the sample I knocked up to test this
>> scenario:
>>
>> public string GetTypes()
>> {
>> using System.Web;
>> StringBuilder sb = new StringBuilder();
>> sb.Append(HttpContext.Session["UserID"].ToString());
>> return(sb.ToString());
>> }
>>
>> The following message is generated:
>>
>> An object reference is required for the nonstatic field,
>> method, or property 'System.Web.HttpContext.Session'.
>>
>> Do I need to pass the HTTPContext object to the middle
>> tier object through a method parameter?
>>
>> >-----Original Message-----
>> >You could just use the HttpContext object from your

>> business tier.
>> >Or if you want your business objects to be more generic

>> so they could be
>> >used from other (non-web) front ends in the future then

>> you may just want to
>> >only pass value types as parameters to your business

>> objects. In this case
>> >your page objects would extract the necessary

information
>> from session state
>> >so the business objects don't need to deal with any web

>> stuff.
>> >
>> >--
>> >I hope this helps,
>> >Steve C. Orr, MCSD, MVP
>> >http://Steve.Orr.net
>> >Hire top-notch developers at http://www.able-

>> consulting.com
>> >
>> >
>> >
>> >"Glenn" <> wrote in

>> message
>> >news:036c01c3d4aa$6f2db0a0$...
>> >> Hi,
>> >>
>> >> I know that I can access session state on an asp.net

>> page
>> >> using either HttpContext or Page objects, but how do

I
>> >> access session data from middle tiers?
>> >>
>> >> Should the technique be to extricate the necessary

>> session
>> >> data with a web page and pass this to the business

tier?
>> >>
>> >> If I need to alter session state in a middle tier

>> object,
>> >> should I use a reference parameter and update the

>> session
>> >> state when the method call is complete?
>> >>
>> >> Thanks,
>> >>
>> >> Glenn.
>> >
>> >
>> >.
>> >

>
>
>.
>

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Does Caching below in the business tier or data tier?? Nemisis ASP .Net 1 08-22-2006 03:43 PM
Setting up a new tier in a 3-tier system? Steve Kershaw ASP .Net 3 03-29-2006 01:09 AM
2 tier to 3 tier? NOSPAM ASP .Net 1 10-14-2004 10:51 PM
ASP v2 & 3-tier or 2-tier rob ASP .Net 1 08-13-2004 06:04 AM
Converting a 2-tier application to 3-tier application Shantanu Bhattacharya C++ 2 12-26-2003 02:04 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57