LogOut Session无法正常工作 [英] LogOut Session is not working
本文介绍了LogOut Session无法正常工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
您好。我有一点问题。一旦用户登录,他们就可以在欢迎页面上注销,但我也可以在其他页面上注销按钮,当用户点击注销按钮时没有任何反应。我做错了什么或忘记了什么?这是我放置注销按钮的页面不起作用。
Hello. I have a little problem. Once a user logs in they can log out on the welcome page but I but a log out button on the other pages as well and when the user clicks the logout button nothing happens. What did I do wrong or forget? This is the page I put the logout button on that does not work.
using System;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Drawing;
using System.Text;
using System.Data;
using System.Collections.Generic;
using System.Linq;
using System.Data.SqlClient;
using System.Configuration;
using System.Drawing.Printing;
public partial class FinancialProfileFormC : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void ButtonSubmit_Click(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["PassConnectionString"].ConnectionString);
con.Open();
string insCmd = "Insert into TableFIN (FINYR, INSTRUCTIO, RESEARCH, PUBLIC_SER, ACADEMIC_S, STUDENT_SE, INSTITUTIO, PHYSICAL_P, SCHOLARSHI, AUXILIARY_, HOSPITALS, INDEPENDEN, OTHEREXP) values (@FINYR, @INSTRUCTIO, @RESEARCH, @PUBLIC_SER, @ACADEMIC_S, @STUDENT_SE, @INSTITUTIO, @PHYSICAL_P, @SCHOLARSHI, @AUXILIARY_, @HOSPITALS, @INDEPENDEN, @OTHEREXP)";
SqlCommand insertUser = new SqlCommand(insCmd, con);
insertUser.Parameters.AddWithValue("@FINYR", TextBoxCYF.Text);
insertUser.Parameters.AddWithValue("@TOTSL_REVE", TextBoxTRIR);
insertUser.Parameters.AddWithValue("@INSTRUCTIO", TextBoxInstr.Text);
insertUser.Parameters.AddWithValue("@RESEARCH", TextBoxRes.Text);
insertUser.Parameters.AddWithValue("@PUBLIC_SER", TextBoxPubS.Text);
insertUser.Parameters.AddWithValue("@ACADEMIC_S", TextBoxAcad.Text);
insertUser.Parameters.AddWithValue("@STUDENT_SE", TextBoxStudS.Text);
insertUser.Parameters.AddWithValue("@INSTITUTIO", TextBoxInstiS.Text);
insertUser.Parameters.AddWithValue("@PHYSICAL_P", TextBoxOperM.Text);
insertUser.Parameters.AddWithValue("@NET_AID", TextBoxNGAS.Text);
insertUser.Parameters.AddWithValue("@AUXILIARY_", TextBoxAuxE.Text);
insertUser.Parameters.AddWithValue("@HOSPITALS", TextBoxHosS.Text);
insertUser.Parameters.AddWithValue("@INDEPENDEN", TextBoxIndeO.Text);
insertUser.Parameters.AddWithValue("@OTHEREXP", TextBoxOE.Text);
try
{
insertUser.ExecuteNonQuery();
con.Close();
Response.Redirect("FinancialIndicatorsForm.aspx");
}
catch (Exception er)
{
Response.Write("You Have Successfully Submitted the Information!!!");
}
finally
{
}
}
protected void ButtonPrint_Click(object sender, EventArgs e)
{
}
protected void ButtonLogout_Click(object sender, EventArgs e)
{
Session["New"] = null;
Response.Redirect("Login.aspx");
}
}
以下代码可以正常工作。
Here is the code that does work.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class IALOPage : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
Session["New"] = null;
Response.Redirect("Login.aspx");
}
}
推荐答案
使用
Session.Clear()
或
Session.Abandon()
此处更多信息http://msdn.microsoft.com/en-us/library/system.web.sessionstate .httpsessionstate.clear.aspx [ ^ ]
http://msdn.microsoft.com/en-us/library/system.web.sessionstate.httpsessionstate.abandon.aspx [ ^ ]
试试这个...... :)
Try This....:)
protected void ButtonLogout_Click(object sender, EventArgs e)
{
Session.Abandon();
Session.Clear();
Response.Redirect("Login.aspx");
}
这篇关于LogOut Session无法正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文