我創建了一個簡單的登錄頁面asp.net這需要用戶名和密碼的文本框,並與我已經存儲在數據庫和一個比較只有重定向如果是一樣的存儲在數據庫中。實現asp.net登錄和註銷
但正在發生的事情是,當我登錄,然後按返回鍵,然後再向前擠瀏覽器的按鈕回去,它仍然將用戶重定向。
所以任何人都可以幫助解決這個問題,因爲一旦註銷,它應該只在輸入憑據後重定向,而不是通過按下瀏覽器的按鈕。
protected void LoginButton_Click(object sender, EventArgs e)
{
int results = 0;
if (txtUsername.Text != "" && txtPassword.Text != "")
{
results = Validate_Login(txtUsername.Text, txtPassword.Text);
}
else
{
lblMessage.Text = "Please make sure that the username and the password is Correct";
}
if (results == 1)
{
if (txtUsername.Text.Equals("admin"))
{
Response.Redirect("~/ConfigurationPage.aspx");
}
else
{
Response.Redirect("");
}
}
else
{
lblMessage.Text = "Invalid Login";
lblMessage.ForeColor = System.Drawing.Color.Red;
}
}
public int Validate_Login(String username, String password)
{
var conString = ConfigurationManager.ConnectionStrings["ConnectionString"];
string strConnString = conString.ConnectionString;
int results = 0;
using (SqlCommand cmdselect = new SqlCommand
{
CommandType = CommandType.StoredProcedure,
CommandText = "[dbo].[prcLoginv]"
})
{
cmdselect.Parameters.Add("@Username", SqlDbType.VarChar, 50).Value = username;
cmdselect.Parameters.Add("@UPassword", SqlDbType.VarChar, 50).Value = password;
cmdselect.Parameters.Add("@OutRes", SqlDbType.Int, 4);
cmdselect.Parameters["@OutRes"].Direction = ParameterDirection.Output;
try
{
if (connection == null)
{
connection = new SqlConnection(strConnString);
connection.Open();
cmdselect.Connection = connection;
cmdselect.ExecuteNonQuery();
results = (int) cmdselect.Parameters["@OutRes"].Value;
}
else if (connection.State == ConnectionState.Closed)
{
connection.Open();
cmdselect.ExecuteNonQuery();
results = (int) cmdselect.Parameters["@OutRes"].Value;
}
}
catch (SqlException ex)
{
lblMessage.Text = ex.Message;
}
finally
{
if (connection != null)
{
connection.Close();
}
}
}
return results;
}
我們需要你的一些代碼來更好地幫助你。請修改您的帖子併發布您的相關代碼。 –
所以我不確定你真的在檢查證書和/或使用會話對象。你需要發佈**相關的**代碼。 – gideon
我已經添加了我的代碼..感謝您的建議:) –