我创建了一个简单的登录页面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
我已经添加了我的代码..感谢您的建议:) –