会话放弃在ASP.NET中不起作用
本文关键字:不起作用 NET ASP 放弃 会话 | 更新日期: 2023-09-27 18:01:14
我开发了一个网站,并在会话中存储数据。如果用户退出会话,我必须在会话中设置数据。
Logout.aspx:
protected void Page_Load(object sender, EventArgs e)
{
try
{
WebUser user = (WebUser)Session["User"];
Session["User"] = null;
Session.Abandon();
if (user != null)
SentiWordnetUtils.LogYaz(user.uAdi + "'t Çıkış Yaptı");
if ((Request.Cookies["OturumRef"] != null))
Response.Cookies["OturumRef"].Value = string.Empty;
Response.Redirect("Login.aspx");
}
catch (Exception ex)
{
LogYaz( "Oturum Sonlandırma Hatası "+ex.Message.ToString());
}
}
global.asax:中的session_end函数
void Session_End(object sender, EventArgs e)
{
List<TBL_SentiWordNet> tempList = (List<TBL_SentiWordNet>)Session["listProcess"];
if (tempList == null)
return;
using (DataClassesDataContext dc = new DataClassesDataContext())
{
foreach (TBL_SentiWordNet word in tempList)
{
var a = (from i in dc.TBL_SentiWordNets where i.id == word.id select i).FirstOrDefault();
a.state = 0;
}
dc.SubmitChanges();
}
Session["listProcess"]= null;
Session["User"] = null;
}
此代码适用于本地,但不适用于IIS。a.state永远不是0
web.config:
<?xml version="1.0" encoding="UTF-8"?>
<!--
For more information on how to configure your ASP.NET application, please visit
http://go.microsoft.com/fwlink/?LinkId=169433
-->
<configuration>
<system.web>
<sessionState mode="InProc" timeout="30" />
<compilation debug="true" targetFramework="4.0">
<assemblies>
<add assembly="System.Transactions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089" />
<add assembly="System.Data.Linq, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089" />
</assemblies>
</compilation>
</system.web>
<connectionStrings>
<add name="myconnectionstring" connectionString="Data Source=127.0.0.1;Initial Catalog=mydb;Persist Security Info=True;User ID=userID;Password=password" providerName="System.Data.SqlClient" />
</connectionStrings>
<system.webServer>
<defaultDocument>
<files>
<clear />
<add value="default.aspx" />
<add value="Default.htm" />
<add value="Default.asp" />
<add value="index.htm" />
<add value="index.html" />
<add value="iisstart.htm" />
</files>
</defaultDocument>
</system.webServer>
</configuration>
Session End从未真正启动,因为当它执行时,它是在页面请求完成并且请求已经发送到客户端之后。
您需要在页面中或在基本页面类中执行session_end代码(这类代码非常方便(。
参见以下S.O.链接:
Session_End不启动?
会话放弃((和会话清除((之间的区别是什么