Session Object = nothing?

L

Lucas Tam

I'm calling the session object from an inherited page. The page is based
off an herited class which outputs XML.

Does anyone know why the session object would be nothing?

httpcontext.current.request/response/etc all work, except for session.

Thanks.
 
R

Roy

I don't have your answer Lucas, but I'd like to hear what it is all the
same. I've run into this same problem myself. Are there any thorough
sites online that have in-depth info on the Session object?

For instance, if I set a session variable on page1, and someone clicks
a button which uses a Response.Redirect to send them to page2, why is
it that the session variable is no longer recognized as being set? The
compiler errors out on me. I assume it's because Response.Redirect is
not a good method of "linking" pages together into a session? If so,
then what is? Not trying to hijack this thread, I just think there's
skimpy info on the web concerning session objects (what makes life a
little more interesting for me is I don't have access to VS.NET)...
 
J

Juan T. Llibre

re:
For instance, if I set a session variable on page1,
and someone clicks a button which uses a
Response.Redirect to send them to page2,
why is it that the session variable is no longer
recognized as being set?

I don't understand your problem, Roy.

See http://asp.net.do/test/Session1.aspx and click the redirect button.

The session variable set in session1.aspx is written to the session2.aspx page.

No problem.

Here's the code for both aspx pages :

session1.aspx:
----------------------
<%@ Page Language="VB" %>
<script runat="server">
Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs)
Response.Redirect("/test/Session2.aspx")
End Sub
</script>
<html>
<head>
<title>Session 1</title>
</head>
<body>
<%Session("testRedirect") = "My Test Session Redirect Variable"%>
<form id="form1" runat="server">
<asp:Button ID="Button1" Runat="server" Text="Redirect" OnClick="Button1_Click" />
</form>
</body>
</html>
----------------

session2.aspx:
----------------------
<%@ Page Language="VB" %>
<html>
<head>
<title>Session2.aspx</title>
</head>
<body>
<%=Session("testRedirect")%>
</body>
</html>
 
J

Joe Fallon

I have run into this enough that I no longer try to "optimize" my pages by
limiting the type of Session for each.
On some pages you can have full access to the Session while on others you
can set it to None or ReadOnly which is a minor performance improvement.
Whenever I went beck to edit those pages and I changed the code to use
Session it would fail. Then I would spend 10 minutes trying to figure out
why when I was the dope that had turned it off.

Hopefully, that is all you did too!
 
R

Roy

Juan,

I tried your two pages and they run fine. My problem occurs in that I'm
trying to access the session variables within VB code. Example:

Dim empSelect As Object = DropDownList1.SelectedItem.Text.Replace("'",
"''")
If (infoSelect = "") Then
InfoBox()
Else
<%Session("sesInfo") = infoSelect%>
Response.Redirect("Main.aspx")
End If

This does not work. It errors out on the Session variable line. When I
remove the surrounding <% %> it doesn't error out and the redirect
works, but then it does error out on Main.aspx.
:-/
 
R

Roy

Never mind Juan. I honestly have no clue what I just did, but this
particular example is working now.
 
L

Lucas Tam

I have run into this enough that I no longer try to "optimize" my
pages by limiting the type of Session for each.
On some pages you can have full access to the Session while on others
you can set it to None or ReadOnly which is a minor performance
improvement. Whenever I went beck to edit those pages and I changed
the code to use Session it would fail. Then I would spend 10 minutes
trying to figure out why when I was the dope that had turned it off.

Hopefully, that is all you did too!

It seems ASP.NET drops sessions on recompile... and it was affect one of my
pages.
 

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,764
Messages
2,569,567
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top