For CS
protected void lnkLogOut_Click(object sender, EventArgs e)
{
CLMSDataContext context = new CLMSDataContext();
try
{
Object uid = Session["User_Idx"];
Dim_User usr = context.Dim_Users.Single(u => u.User_Idx == Convert.ToInt32(uid));
Session["User_Idx"] = null;
Session["fullname"] = null;
Session["errorlog"] = null;
Session.Clear();
//usr.Status = null;
context.SubmitChanges();
Response.Redirect("~/Login.aspx");
Server.Transfer("Login.aspx");
}
catch (Exception ex)
{
Response.Write(ex.Message);
}
finally
{
context.Dispose();
}
}
For ASPX
<%
if (Session["User_Idx"] == null)
{
Response.Redirect("Login.aspx");
}
else
{
%>
Welcome <% Response.Write(Session["Fullname"]); %> |
<%}%>


Krishna GaradRank #191 · 12.8K reputationPosted Nov 23, 2012, 1:20 AM EST
mary jean ligasRank #3,676 · 400 reputationPosted Nov 23, 2012, 1:24 AM EST
Session.Abandon();
Session.RemoveAll();
Session.Clear();
But still when i clicked browsers back button the session never expire..
Krishna GaradRank #191 · 12.8K reputationPosted Nov 23, 2012, 2:18 AM EST
Suthish NairRank #92 · 22.8K reputationPosted Nov 23, 2012, 2:37 AM EST
Session["User_Idx"] = null;
Session["fullname"] = null;
Session["errorlog"] = null;
Session.Clear();
Add
Session.RemoveAll();
Session.Clear();
Session.Abandon();
Response.AppendHeader("Cache-Control", "no-store");
Response.Cookies.Add(new HttpCookie("ASP.NET_SessionId", ""));
Response.Cache.SetCacheability(HttpCacheability.NoCache);
Then redirect.. this will prevent Session Hijacking also...