is this the right section for visual c#.net?
session destroy wont work if i use internet explorer 9, but in google chrome it's working..
the problem in IE 9 is that, when i logout then i press the back button on the browser the session variable still exist, but when i hit enter key on the url address bar it destroy the session variable what approach should i do?
i'm creating a simple login/logout.
i have two aspx file
Code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace CT2
{
public partial class WebForm1 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if ((string)(Session["users"])!=null)
{
Session.Clear();
Session.Abandon();
Session.RemoveAll();
}
}
protected void login_Click(object sender, EventArgs e)
{
var users= username.Text;
var pass= password.Text;
if (users== "admin" && pass== "admin")
{
//Response.Write("<script>alert('successfully login!')</script>");
Session["users"]=users;
Response.Redirect("user.aspx");
/*HttpContext CurrContext = HttpContext.Current;
CurrContext.Items.Add("users",Id_User);
Server.Transfer("user.aspx");
*/
}else if(users!="admin" || pass!="admin"){
Response.Write("<script>alert('incorrect username and password')</script>");
username.Text = "";
password.Text = "";
}
}
}
}
Code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace CT2
{
public partial class user : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
/* HttpContext CurrContext = HttpContext.Current;
NameOfUser.Text = CurrContext.Items["users"].ToString();
*/
if ((string)(Session["users"]) != null)
{
NameOfUser.Text = (string)(Session["users"]);
}
else
{
Session.Clear();
Session.Abandon();
Session.RemoveAll();
Response.Redirect("WebForm1.aspx");
}
}
protected void Button1_Click(object sender, EventArgs e)
{
Session.Clear();
Session.Abandon();
Session.RemoveAll();
Response.Redirect("WebForm1.aspx");
}
}
}