Session state doesn't refresh

N

Ned Balzer

Hi,

Apologies if this is a newbie question, I haven't found the answer in
any faqs.

I have an asp.net 2.0 page that sets session variables and then
redirects to another page. For the page that gets redirected to, I've
swapped in a simple page for testing that reads the session variables
and displays their values.

I've noticed that consistently, when I go back to the first page and
change session var values (the same values, not creating any new ones),
after the redirect, the displaying page still displays the previous
values. I have to click the refresh button on the displaying page
before I see the new values.

Is there a way for me to force the displaying page to not cache the old
values? My page is very simple, and so is my web.config file, I don't
think I have caching turned on anywhere, so I am surprised that this
apparent caching is happening (if it is indeed a caching problem, I
don't even know that for sure). I would have thought the default was
not to cache.

TIA.

-- Ned Balzer
 
C

Cowboy \(Gregory A. Beamer\)

It may be due to ViewState. Turn off ViewState and see if it works.
Otherwise, post some code and see if one of us can help you out.

--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA

*************************************************
Think Outside the Box!
*************************************************
 
N

Ned Balzer

Thanks much.

OK the way this works, default.aspx checks to see if Session("LoginOK")
is 0 (the default), and if so, redirects to
session_swap.aspx?username=emb23 (a test value). session_swap.aspx
looks up the username in a database and checks if that username is
valid, and if so, whether it can impersonate some other username. If
it is valid but isn't allowed to impersonate, it's redirected back to
default.aspx. If it is allowed to impersonate, the redirect goes to
prefs.aspx, so the user can choose whom to impersonate. Finally, the
user ends back at default.aspx (or is supposed to end up back there).
The various pages seem to read the session vars very inconsistently,
sometimes they are up to date and sometimes not, it seems to have no
rhyme or reason to me.

Here are the three aspx pages.

Thanks again, this is probably something simple, but I just can't see
what it is.

-- Ned

PS I know there are better ways to do this, like use the authentication
and membership controls, but I need to get this working first and
refine later.

default.aspx:
<%@ Page Explicit="True" Language="VB" Debug="True" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">

<script runat="server">
Protected Sub Page_Load(ByVal sender As Object, ByVal e As
System.EventArgs)
If Session("loginOK") = 0 Then
Response.Redirect("Session_swap.aspx?username=emb23",
False)
Else
'If Session("onBehalfOfOK") = 0 Then
' Response.Redirect("prefs.aspx", False)
'End If
End If
If Session("onBehalfOfOK") = 0 Then
'Response.Redirect("prefs.aspx", False)
End If

End Sub
</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1" runat="server">
<title>My Publications</title>
</head>
<body>

<form id="form1" runat="server">
<div>
<font size="3" face="Arial">
<p>Click the various links to see your publications in the current
year.</p>
</font>
<asp:label id="thecategories" runat="server" font-size="18 pt"
font-name="Arial" font-bold="true"
text="Types of Publications:" /><br><br>
<ul>
<li>
<asp:hyperlink id="ArticleLink" runat="server"
navigateurl="articlegrid.aspx"
font-name="Arial" font-size="16">
Articles</asp:hyperlink>
</li>
<li>
<asp:hyperlink id="BooksLink" runat="server"
navigateurl="bookgrid.aspx"
font-name="Arial" font-size="16 pt">
Books</asp:hyperlink>
</li>
<li>
<asp:hyperlink id="ChaptersLink" runat="server"
navigateurl="chaptergrid.aspx"
font-name="Arial" font-size="16 pt">
Book Chapters</asp:hyperlink>
</li>
<li>
<asp:hyperlink id="CollectionsLink" runat="server"
navigateurl="monographgrid.aspx"
font-name="Arial" font-size="16 pt">
Monographs</asp:hyperlink>
</li>
<li>
<asp:hyperlink id="SearchLink" runat="server"
navigateurl="search.aspx"
font-name="Arial" font-size="16 pt">
Search</asp:hyperlink>
</li>
</ul>
</div>
</form>
</body>
</html>

session_swap.aspx:
<%@ Page Language="VB" %>
<%@ Import Namespace="System.Data" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<script runat="server">
Protected Sub Page_Load(ByVal sender As Object, ByVal e As
System.EventArgs)
Session("username") = Request.QueryString("username")
End Sub

Protected Sub Page_PreRender(ByVal sender As Object, ByVal e As
System.EventArgs)
SqlDataSource1.DataBind()
Dim myResultLbl1 As Label = CType(FV1.FindControl("loginOK"),
Label)
Dim myResult1 As Int32 = CType(myResultLbl1.Text, Int32)
If myResult1 = 0 Then
Session("loginOK") = 0
Response.Redirect("noSuchUser.aspx", False)
End If
Dim myResultLbl2 As Label = CType(FV1.FindControl("dept"),
Label)
Dim myResult2 As String = myResultLbl2.Text
Dim myResultLbl3 As Label = CType(FV1.FindControl("myName"),
Label)
Dim myResult3 As String = myResultLbl3.Text
Dim myResultLbl4 As Label = CType(FV1.FindControl("isFac"),
Label)
Dim myResult4 As Int32 = CType(myResultLbl4.Text, Int32)
Session("loginOK") = 1
SqlDataSource2.DataBind()
Dim myResultLbl5 As Label =
CType(FV2.FindControl("canActOnBehalfOf"), Label)
Dim myResult5 As Int32 = CType(myResultLbl5.Text, Int32)
If myResult5 < 2 Then 'single
Session("canActOnBehalfOf") = 0
Session("onBehalfOfOK") = 1
Session("dept") = myResult2
Session("myName") = myResult3
Session("isFac") = myResult4
Session("facMember") = Session("username")
Session("otherName") = myResult3
Response.Redirect("default.aspx", False)
Else 'multiple
Session("canActOnBehalfOf") = 1
'Session("onBehalfOfOK") = 0
Session("myName") = myResult3
Response.Redirect("prefs.aspx", False)
End If
End Sub

</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<asp:FormView ID="FV1" runat="server"
Visible="false"
DataSourceID="SqldataSource1">
<ItemTemplate>
<asp:Label ID="loginOK" runat="server" Text='<%#
Eval("loginOK") %>' />
<asp:Label ID="dept" runat="server" Text='<%# Eval("dept")
%>' />
<asp:Label ID="myName" runat="server" Text='<%#
Eval("myName") %>' />
<asp:Label ID="isFac" runat="server" Text='<%#
Eval("isFac") %>' />
</ItemTemplate>
</asp:FormView>

<asp:FormView ID="FV2" runat="server"
Visible="false"
DataSourceID="SqldataSource2">
<ItemTemplate>
<asp:Label ID="canActOnBehalfOf" runat="server" Text='<%#
Eval("canActOnBehalfOf") %>' />
</ItemTemplate>
</asp:FormView>

<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$
ConnectionStrings:lapubsDBConnectionString %>"
ProviderName="<%$
ConnectionStrings:lapubsDBConnectionString.ProviderName %>"
SelectCommand="select count(psuid) as loginOK, max(dept) as
dept, max(fullName) as myName, max(faculty_member) as isFac from
v_logins where psuid = @psuid" >
<SelectParameters>
<asp:QueryStringParameter Name="psuid"
QueryStringField="username" />
</SelectParameters>
</asp:SqlDataSource>

<asp:SqlDataSource ID="SqlDataSource2" runat="server"
ConnectionString="<%$
ConnectionStrings:lapubsDBConnectionString %>"
ProviderName="<%$
ConnectionStrings:lapubsDBConnectionString.ProviderName %>"
SelectCommand="select count(psuid) as canActOnBehalfOf from
v_proxies where psuid = @psuid" >
<SelectParameters>
<asp:QueryStringParameter Name="psuid"
QueryStringField="username" />
</SelectParameters>
</asp:SqlDataSource>

</form>
</body>
</html>

prefs.aspx:
<%@ Page Language="VB" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<script runat="server">
Protected Sub Page_Load(ByVal sender As Object, ByVal e As
System.EventArgs)
oBoSqlDataSource.DataBind()
End Sub

Protected Sub btnSubmit_click(ByVal sender As Object, ByVal e As
System.EventArgs)
Dim myResultddl1 As DropDownList =
CType(form1.FindControl("ddlOther"), DropDownList)
Dim myResult1 As String = myResultddl1.SelectedValue
oBoInfoSqlDataSource.SelectParameters("psuID").DefaultValue =
Session("username")

oBoInfoSqlDataSource.SelectParameters("onBehalfOf").DefaultValue =
myResult1
oBoInfoSqlDataSource.DataBind()
Dim myResultddl2 As DropDownList =
CType(form1.FindControl("ddlOtherDept"), DropDownList)
Dim myResult2 As String = myResultddl2.SelectedValue
Dim myResultLbl3 As Label = CType(FV1.FindControl("otherName"),
Label)
Dim myResult3 As String = myResultLbl3.Text
Dim myResultLbl4 As Label =
CType(FV1.FindControl("faculty_member"), Label)
Dim myResult4 As Int32 = CType(myResultLbl4.Text, Int32)
Session("dept") = myResult2
Session("isFac") = myResult4
Session("facMember") = myResult1
Session("otherName") = myResult3
Session("onBehalfOfOK") = 1
Response.Redirect("default.aspx", False)
End Sub
</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Act On Behalf Of</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<h1>Choose whom to login on behalf of:</h1>
<asp:Label ID="lblMyName"
Text="You Are: "
AssociatedControlID="myName"
runat="server" />
<asp:Label ID="myName"
Text='<%# Eval(Session("username")) %>'
runat="server" />
<br />
<asp:Label ID="lblDdlOther"
Text="Acting On Behalf Of: "
AssociatedControlID="ddlOther"
runat="server" />
<asp:DropDownList ID="ddlOther"
DataSourceID="oBoSqlDataSource"
DataTextField="otherName"
DataValueField="onBehalfOf"
RunAt="server" />
<br />
<asp:Label ID="lblDdlDept"
Text="Department: "
AssociatedControlID="ddlOtherDept"
runat="server" />
<asp:DropDownList ID="ddlOtherDept"
DataSourceID="oBoDeptSqlDataSource"
DataTextField="otherDept"
DataValueField="otherDept"
RunAt="server" />
<br />
<asp:Button ID="btnSubmit" OnClick="btnSubmit_click" text="Submit"
runat="server" />

<asp:FormView ID="FV1" runat="server"
Visible="false"
DataSourceID="oBoInfoSqlDataSource">
<ItemTemplate>
<asp:Label ID="onBehalfOf" runat="server" Text='<%#
Eval("onBehalfOf") %>' />
<asp:Label ID="otherDept" runat="server" Text='<%#
Eval("otherDept") %>' />
<asp:Label ID="otherName" runat="server" Text='<%#
Eval("otherName") %>' />
<asp:Label ID="Faculty_member" runat="server" Text='<%#
Eval("Faculty_member") %>' />
</ItemTemplate>
</asp:FormView>


<asp:SqlDataSource ID="oBoSqlDataSource" runat="server"
ConnectionString="<%$
ConnectionStrings:lapubsDBConnectionString %>"
ProviderName="<%$
ConnectionStrings:lapubsDBConnectionString.ProviderName %>"
SelectCommand="select onBehalfOf, otherName, otherDept from
v_proxies_expanded where psuid=@psuid order by psuid, dispOrder,
otherName" >
<SelectParameters>
<asp:SessionParameter Name="psuid" SessionField="username" />
</SelectParameters>
</asp:SqlDataSource>

<asp:SqlDataSource ID="oboDeptSqlDataSource" runat="server"
ConnectionString="<%$
ConnectionStrings:lapubsDBConnectionString %>"
ProviderName="<%$
ConnectionStrings:lapubsDBConnectionString.ProviderName %>"
SelectCommand="select distinct otherDept from
v_proxies_expanded where psuid=@psuid order by otherDept" >
<SelectParameters>
<asp:SessionParameter Name="psuid" SessionField="username" />
</SelectParameters>
</asp:SqlDataSource>

<asp:SqlDataSource ID="oBoInfoSqlDataSource" runat="server"
ConnectionString="<%$
ConnectionStrings:lapubsDBConnectionString %>"
ProviderName="<%$
ConnectionStrings:lapubsDBConnectionString.ProviderName %>"
SelectCommand="select onBehalfOf, Faculty_member, otherName,
otherDept from v_proxies_expanded where psuid=@psuid and
onBehalfOf=@onBehalfOf" >
<SelectParameters>
<asp:SessionParameter Name="psuid" SessionField="username" />
<asp:parameter Name="onBehalfOf" Type="String" />
</SelectParameters>
</asp:SqlDataSource>



</div>
</form>
</body>
</html>
 

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,770
Messages
2,569,583
Members
45,074
Latest member
StanleyFra

Latest Threads

Top