繁体   English   中英

IIS7 ASP.NET会话在几秒钟内下降

[英]IIS7 ASP.NET Session drops in seconds

为了进行测试,我有1个独立的页面-没有主控件,控件等。 大约30秒后,我的会话丢失。 我尝试过在网页本身,web.config和/或两者中都设置超时。 尝试使用超时和Windows身份验证进行表单身份验证。 更改后回收AppPool。

我可以从Session_Start进行response.write,但是我从Session_End从未得到任何response.writes。

我尝试过的一些事情:

<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"/>

没运气。

我的运行时设置为:

<httpRuntime useFullyQualifiedRedirectUrl="true" 
maxRequestLength="204800" 
requestLengthDiskThreshold="204800" 
executionTimeout="600" />

我不知道这有什么意义,但我想不出其他任何东西!

谢谢!

如果您正在执行Inproc会话(如代码段所示),并且某物不断接触虚拟文件夹或虚拟文件夹下的任何内容,则可能会丢失很多会话。

如果是这种情况,请解决此问题:

'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() {})

您怎么知道您的会话丢失了? 您的浏览器是否启用了cookie?

编辑:
这是一个非常简单的测试页面:

<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>

以及后面的代码:

public partial class SessionTest : System.Web.UI.Page
{
    protected void btnSet_Click(object sender, EventArgs e)
    {
        Session["testvalue"] = txtText.Text;
    }
}

另一种可能是由于重新启动应用程序域而丢失了会话。 将某种日志记录输出添加到Application_Start。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM