여기에있는 코드는 C #과 함께 ASP.NET을 사용하고 있습니다. 문제는 사용자가 로그 아웃 버튼을 클릭하면 사용자가 이전 페이지로 돌아갈 수 있다는 것입니다.
로그인 코드
protected void Page_Load(object sender, EventArgs e)
{
Session["email"] = txtemail.Text;
}
protected void btlogin_Click(object sender, EventArgs e)
{
SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["connection"].ConnectionString);
SqlCommand cmd = conn.CreateCommand();
cmd.CommandText = "SELECT [email], [password] FROM [customer] WHERE [email]=@email AND [password]=@password";
cmd.Parameters.Add("@email", SqlDbType.VarChar).Value = txtemail.Text;
cmd.Parameters.Add("@password", SqlDbType.VarChar).Value = txtpassword.Text;
conn.Open();
SqlDataReader reader = cmd.ExecuteReader();
if (reader.Read())
{
Response.Redirect("~/Booking.aspx");
reader.Close();
conn.Close();
}
else
{
lb.Text="Email or Password incorrect";
}
}
}
로그 아웃 코드
protected void Page_Load(object sender, EventArgs e)
{
if (Session["email"] == null)
{
Response.Redirect("Default.aspx");
}
}
protected void btlogout_Click(object sender, EventArgs e)
{
Session["email"] = null;
Response.Redirect("Default.aspx");
}
사용자가 로그 아웃 한 후 이전 페이지에 액세스하지 못하도록하는 방법
여러 가지 방법이 있습니다
Session
사용 Session.Abandon
및 사용 지우기Response.Redirect("~/LoginPage.aspx");
그런 다음 다음 방법을 사용하여 캐시를 지우거나 기록을 지울 수 있습니다.
Codebehind 사용
// Code disables caching by browser.
Response.Cache.SetCacheability(HttpCacheability.NoCache);
Response.Cache.SetExpires(DateTime.UtcNow.AddHours(-1));
Response.Cache.SetNoStore();
JavaScript 사용
<SCRIPT LANGUAGE="javascript">
function ClearHistory()
{
var backlen = history.length;
history.go(-backlen);
window.location.href = loggedOutPageUrl
}
</SCRIPT>
asp.net 사용
업데이트 패널없이
Page.ClientScript.RegisterStartupScript(this.GetType(),
Guid.NewGuid().ToString(),"ClearHistory();",true);
업데이트 패널 포함
ScriptManager.RegisterStartupScript(this,this.GetType(),
Guid.NewGuid().ToString(),"ClearHistory();",true);
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다