Default1.aspx

protected void Button1_Click1(object sender, EventArgs e)
    {
        Session["name"] = TextBox1.Text;
        Response.Redirect("Default2.aspx");
    }

Default2.aspx

protected void Page_Load(object sender, EventArgs e)
    {

        string sBeforeAbandon;
        string sAfterAbandon;

        sBeforeAbandon = Session["name"].ToString ();
        Session.Abandon();
        if (Session["name"] != null)
        {
            sAfterAbandon = Session["name"].ToString();
        }

Hey frnds Session.Abandon clears all the session on the next page,If i access suppose this session value in Defaul3.aspx,then session value is not retrieved..But i also want that in sAfterAbandon value cannot be access,Which statement i have to write above this statement,so dat i m not able to access d session??

Secondly tell me dat is there any method Session.kill() in ASP.net????

Session.Abandon() is what you are looking for. You cant very well throw an error if the session has been abandoned because you don't have a place to store if it has been abandoned since you're clearing the session. Likewise when a client requests a new page it will start a new session -- how should the webserver know if the session is a new session from a new browser window, or a new request from an existing browser window?

Are you trying to figure out how to keep users logged in -- and if you abandon the session have it log them out and redirect them to a certain area?

[edit]Actually you can Call Response.Flush() and an exception will throw if you try to access the session state after the response has been sent[/edit]

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.