SessionState - HELP

K

Krishnan

Hi,
Could anyone please let me know how to read SessionState setting from the
Web.Config file into an ASPNET application?

TIA
Krishnan
 
H

Hans Kesting

Krishnan said:
Hi,
Could anyone please let me know how to read SessionState setting from
the Web.Config file into an ASPNET application?

TIA
Krishnan

What exactly are you trying to do?
You can access some of the values with Session.IsCookieless
and Session.Mode

Hans Kesting
 
K

Krishnan

Thanks for your reply.

Am trying to seee if the session state is "InProc", for we need to take some
Serialization decisions based on them. Session.Mode would need
HttpContext.Current and we need to read the settings even in the destructor
(finalize) methods of some classes and they'd not have the HttpContext. So,
is there a way to read the Config without the current HttpContext?

TIA
Krishnan
 
J

Juan T. Llibre

Hi, Krishnan.

You don't have to read web.config to get the Session Mode.

You can read the current Session State Mode with

Page.Session.Mode

GetSessionMode.aspx:
--------------------------
<%@ Page Language="VB" %>
<script runat="server">
sub Page_Load(obj as object, e as eventargs)
lblMessage.Text = Page.Session.Mode.ToString()
End Sub
</script>
<html>
<body>
<asp:Label id="lblMessage" runat="server"/></asp:Label> <br />
</body>
</html>
 
K

Krishnan

Thanks for that, but as I had said in my post, there are situations when I
will not have the HttpContext. So, is there a way to still get the
SessionState?

Thanks
Krishnan
 
J

Juan T. Llibre

I don't think that you can get to the Session mode
without going through the httpContext.

Could you, maybe, retrieve the sessionState mode at any earlier point
where you *do* have access to the httpContext, and save the returned
sessionState mode to a variable which you would be able to retrieve
when you don't have access to the context ?
 
H

Hans Kesting

Krishnan said:
Thanks for your reply.

Am trying to seee if the session state is "InProc", for we need to
take some Serialization decisions based on them. Session.Mode would
need HttpContext.Current and we need to read the settings even in the
destructor (finalize) methods of some classes and they'd not have the
HttpContext. So, is there a way to read the Config without the
current HttpContext?
TIA
Krishnan

As a last resort: the web.config *is* just an xml file, so you could
read in the file and get at the setting yourself. That is, if you just use
*one* web.config ...

Just curious: why would you want to know about the Session.Mode if
you can't access the Session itself at that point?

Hans Kesting
 
K

Krishnan

Thanks for the reply. We resorted to storing the Session Mode in the class.

We need it since we store a com object "as is" into a session case of an
InProc session mode and the same cannot be destroyed in the destructor of
the class (destructor gives no HttpContext as it is a CLR call), but in case
of a StateServer, since the object is serialized, it can be released.

Thanks again.
Krishnan
 

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
474,431
Messages
2,571,677
Members
48,796
Latest member
Greg L.

Latest Threads

Top