session from ServicedComponent

K

Kevin Jackson

If we are using Library ServicedComponents is it possible to get to the
ASP.NET session stuff from a ServicedComponent?
 
S

Steven Cheng[MSFT]

Hi Kevin,


Thanks for posting in the community!
From your description, you wonder if there is any means to access the
ASP.NET's sessionstate in custom ServicedComponent rather than
PageComponent ,yes?
If there is anything I misunderstood, please feel free to let me know.

As for this problem, I think there're two means to use the ASP.NET buildin
objects in a certain library component.
1. Define a certain parameter type of which is one of the ASP.NET buildin
class(such as SessionState, HttpRequest, HttpResponse..). For example:
class component
{
public static void processSession(HttpSessionState session)
{
........
}
}

2. Since the #1 means is limited us to pass a certain object reference to
the component's method, it need us to explicitly use it and set the
parameter in Page's certain events. However, there is another means :
using the HttpContext class , the HttpContext has a static member "Current"
which is the refernce of the currently processed request's HttpContext,
here is the description in MSDN:
-----------------------
You can also use the Context object from your business objects.
HttpContext.Current is a static property that conveniently returns the
context for the current request. This is useful in all kinds of ways, but
here's a simple example of retrieving an item from the cache in your
business class:
--------------------------------
So we can use it to retrieve the current processing request's Request,
Response, Session ... objects in our business components, for example
class component
{
public void processSession()
{
HttpSessionState session = HttpContext.Current.Session;
....
........
}
}

For detailed description, you can view the following tech article in MSDN:
#A Matter of Context
http://msdn.microsoft.com/library/en-us/dnaspnet/html/asp01242002.asp?frame=
true

In addition, here is another tech article discussing the designer pattern
in ASP.NET, I believe it also helpful to you.
#Design and Implementation Guidelines for Web Clients
http://msdn.microsoft.com/library/en-us/dnpag/html/DIforWC-CH02.asp?frame=tr
ue

Please check out the above suggestions. If you have any questions, please
feel free to let me know.


Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Get Preview at ASP.NET whidbey
http://msdn.microsoft.com/asp.net/whidbey/default.aspx
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,022
Latest member
MaybelleMa

Latest Threads

Top