<configuration>
<connectionStrings>
<add name="ApplicationServices" connectionString="data source=.\SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|\aspnetdb.mdf;User Instance=true"providerName="System.Data.SqlClient"/>
</connectionStrings>
<system.web>
<sessionState timeout="1" mode="InProc" cookieless="false" >
</sessionState>
<compilation debug="true" targetFramework="4.0"/>
<authentication mode="Forms">
<forms loginUrl="~/Account/Login.aspx" timeout="1"/>
</authentication>
我創建了一個會話,如果用戶進行身份驗證這樣會話變量
if (HttpContext.Current.User.Identity.IsAuthenticated)
{
string name = HttpContext.Current.User.Identity.Name.ToString();
Session["username"] = name;
}
然後我檢查,如果會話仍然像這裏一樣退出
if (Session["username"] == null)
Response.Redirect("SessionExpired.aspx");
else
Response.Write("session still exist");
**問題:** 1分鐘後會話不變爲空,用戶始終登錄任何幫助
這是代碼:
Welcome to ASP.NET! test1
<p>
To visit test2 go to<asp:LinkButton ID="LinkButton1" runat="server"
onclick="LinkButton1_Click">here</asp:LinkButton>
</p>
<asp:Label ID="msg" runat="server" Text=""></asp:Label>
在服務器端
protected void LinkButton1_Click(object sender, EventArgs e)
{
if (HttpContext.Current.User.Identity.IsAuthenticated)
{
string name = HttpContext.Current.User.Identity.Name.ToString();
Session["username"] = name;
if (Session["username"] == null)
Response.Redirect("~/SessionExpired.aspx");
else
msg.Text = "session still exist the session will be timedout after "+Session.Timeout+ "min";
}
else
Response.Write("please login");
}
你甚至讀過他的問題嗎? mode =「InProc」!!! – Baz1nga 2012-03-31 08:32:32
是的。在我發佈的用戶鏈接也改變了模式「inproc」 – TRR 2012-03-31 08:35:15
這是正確的,在這裏,他不是說他得到它後,改變它的InProc罰款..他面臨的問題,同時使用它.. – Baz1nga 2012-03-31 08:37:21