0
votes

I have developed a web site and I store data in session.If a user abondan the session,I have to set the data in session.

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());
        }

    }

session_end function in global.asax :

  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;


    }

This code is working on local but isn't working on IIS. a.state never isn't 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>
1

1 Answers

1
votes

Session End never truly fires, because when it does execute, it's after the page request is complete and the request has already been sent to the client.

You'll need to do the session_end code in your page, or in a base page class (very handy for this sort of thing).

See the following S.O. links:

Session_End does not fire?

What is the difference between Session.Abandon() and Session.Clear()