如何在asp.net中结束会话? [英] how to end a session in asp .net?
本文介绍了如何在asp.net中结束会话?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
您好,我有两个webforms,一个是登录页面,另一个是主页。每当我点击主页中的注销按钮时,它会重定向到登录页面,如果我点击浏览器中的后退按钮,它会重定向到主页,这不应该发生。现在我的疑问是,每当我点击浏览器中的后退按钮(从主页退出后),它将重定向到登录页面而不是主页。谢谢........
登录页码:
Hello, I have two webforms one is login page and another is home page. Whenever i clicks on logout button in "home page" it redirects to "login page" and if i clicks on "back" button in browser it redirects to home page which shouldn''t be happened. Now my query is that whenever i would click "back" button in browser(after logging out from home page)it would redirect to login page rather than home page. Thanks........
LogIn Page Code:
try
{
Session["ename"] = TextBox1.Text;
cn.Open();
SqlCommand SqlCmd = new SqlCommand("SELECT * FROM empregd WHERE ename='" + TextBox1.Text + "' AND password='" + TextBox2.Text + "'", cn);
SqlDataAdapter SqlDa = new SqlDataAdapter(SqlCmd);
SqlDataReader SqlDr = SqlCmd.ExecuteReader();
if (SqlDr.Read())
{
Response.Redirect("http://localhost:49871/WebSite7/Default6.aspx");
}
SqlDr.Close();
cn.Close();
TextBox1.Text = "";
TextBox2.Text = "";
}
catch (Exception ex)
{
throw ex;
}
首页代码
HomePage Code
protected void Page_Load(object sender, EventArgs e)
{
try
{
if (Session["ename"]== null)
{
Response.Redirect("http://localhost:49871/WebSite7/Default5.aspx");
}
Label2.Text = Session["ename"].ToString();
}
catch (Exception ex)
{
throw ex;
}
}
protected void Button1_Click(object sender, EventArgs e)
{
try
{
Response.Redirect("http://localhost:49871/WebSite7/Default5.aspx");
FormsAuthentication.SignOut();
Session.Abandon();
Session.Clear();
Session["ename"] = null;
}
catch (Exception ex)
{
throw ex;
}
}
推荐答案
以下提示可以帮助你:注销后浏览器后退按钮问题 [ ^ ]
Following Tip should help you out: Browser back button issue after logout[^]
看看这个提示:
注销后的浏览器后退按钮问题 [ ^ ]
这篇关于如何在asp.net中结束会话?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文