Reputation: 179
For testing I have 1 isolated page - no masters, controls, …. My sessions are lost after about 30 seconds. I’ve tried setting timeout on the page itself, in web.config, both, and neither. Tried forms authentication with timeout and windows authentication. Recycle the AppPool after changes.
I can response.write from the Session_Start , but I never get any response.writes from the Session_End.
Some things I’ve tried:
<sessionState mode="InProc"
stateConnectionString="tcpip=127.0.0.1:42424"
sqlConnectionString="data source=127.0.0.1;"
cookieless="false"
timeout="20" />
<sessionState mode="InProc" cookieless="false" timeout="20"/>
<sessionState mode="InProc" timeout="20"/>
<sessionState timeout="20"/>
No luck.
My runtime is set to:
<httpRuntime useFullyQualifiedRedirectUrl="true"
maxRequestLength="204800"
requestLengthDiskThreshold="204800"
executionTimeout="600" />
I don’t know what this would be relevant, but I can’t think of anything else to post!
Thanks!
Upvotes: 0
Views: 3161
Reputation: 43268
If you're doing inproc sessions (which the snippet says you are) and something keeps touching the virtual folder or anything below it be prepared to lose lots of sessions.
If this is the case, this is the fix:
'This is supposed to turn off the monitoring for directory deletes
'See https://connect.microsoft.com/VisualStudio/feedback/Workaround.aspx?FeedbackID=240686
'This incurrs the penelty of an IISRESET or manually restarting the containing AppPool after every upgrade.
Dim pi As PropertyInfo
Dim o As Object
Dim m As MethodInfo
pi = GetType(System.Web.HttpRuntime).GetProperty("FileChangesMonitor", BindingFlags.NonPublic Or BindingFlags.Public Or BindingFlags.Static)
o = pi.GetValue(Nothing, Nothing)
m = o.GetType().GetMethod("Stop", BindingFlags.Instance Or BindingFlags.NonPublic)
m.Invoke(o, New Object() {})
Upvotes: 1
Reputation: 8778
How do you know your Session is being lost? Do you have cookies enabled in your browser?
EDIT:
Here is a much, much simpler test page:
<body>
<form id="form1" runat="server">
<div>
Session value is: <%= Session["testvalue"] %><br />
<asp:TextBox ID="txtText" runat="server"></asp:TextBox>
<asp:Button ID="btnSet" runat="server" Text="Set" OnClick="btnSet_Click" /><br />
<asp:Button ID="btnRefresh" runat="server" Text="Refresh" />
</div>
</form>
</body>
And the code behind:
public partial class SessionTest : System.Web.UI.Page
{
protected void btnSet_Click(object sender, EventArgs e)
{
Session["testvalue"] = txtText.Text;
}
}
Another possibility is that you are losing your sessions due to App domain restarts. Add some sort of logging output to Application_Start.
Upvotes: 0