登录问题,显示错误页面 [英] Login problem , shows error page
本文介绍了登录问题,显示错误页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
登录是我项目中的默认开始页面。登录后只有网站可见,否则进入错误页面。
我的问题我有用户名密码和isctive在我的数据库,但始终只有错误页面可见
我尝试过:
Login is my default start page in my project.after login only website visible,otherwise goes to error page.
in my question i have username password and isctive in my databse,but always error page only visible
What I have tried:
<pre>using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;
public partial class Login : System.Web.UI.Page
{
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["constr"].ConnectionString);
protected void Page_Load(object sender, EventArgs e)
{
try
{
if (!Page.IsPostBack)
{
if (Request.QueryString.Count > 0)
{
string UserID = Request.QueryString["UserID"];
Session["UserID"] = UserID;
Response.Redirect("Default.aspx",false);
}
}
}
catch (Exception ex)
{
Session["Error"] = ex.ToString();
Response.Redirect("Error.aspx");
}
}
protected void btnLogin_Click(object sender, EventArgs e)
{
try
{
if (CheckUsername())
{
if (CheckPassword())
{
RedirectPage();
}
else
{
lblError.Text = "Your login attempt has failed. <BR>Please try again!";
}
}
else
{
lblError.Text = "Your login attempt has failed. <BR>The username or password may be incorrect";
}
}
catch (Exception ex)
{
Session["Error"] = ex.ToString();
Response.Redirect("Error.aspx");
}
}
public bool CheckUsername()
{
string Query = "select * from users where IsActive='True' and Email='" + txtUserName.Text + "'";
DataTable dt = GetData(Query);
if (dt.Rows.Count > 0)
return true;
else
return false;
}
public bool CheckPassword()
{
string Query = "select * from users where IsActive='True' and Email='" + txtUserName.Text + "' and Password='"+txtPassword.Text+"'";
DataTable dt = GetData(Query);
if (dt.Rows.Count > 0)
return true;
else
return false;
}
public DataTable GetData(string Query)
{
SqlCommand cmd = new SqlCommand(Query, con);
SqlDataAdapter sda = new SqlDataAdapter(cmd);
DataTable dt = new DataTable();
sda.Fill(dt);
return dt;
}
public void RedirectPage()
{
string Query = "select top(1) * from users where IsActive='True' and Email='" + txtUserName.Text + "' and Password='" + txtPassword.Text + "'";
DataTable dt = GetData(Query);
if (dt.Rows.Count == 1)
{
Session["UserID"] = dt.Rows[0]["UserID"].ToString();
Response.Redirect("Home.aspx", false);
}
else
{
lblError.Text = "You don't have permission to view this Site!";
Session["UserID"] = "";
}
/*if (dt.Rows.Count == 1)
{
if (Convert.ToBoolean(dt.Rows[0]["Products"]) == true && Convert.ToBoolean(dt.Rows[0]["Users"]) == true)
{
Session["UserID"] = dt.Rows[0]["UserID"].ToString();
Response.Redirect("Default.aspx", false);
}
else if (Convert.ToBoolean(dt.Rows[0]["Products"]) == true && Convert.ToBoolean(dt.Rows[0]["Users"]) == false)
{
Session["UserID"] = dt.Rows[0]["UserID"].ToString();
Response.Redirect("Default.aspx", false);
}
else if (Convert.ToBoolean(dt.Rows[0]["Products"]) == false && Convert.ToBoolean(dt.Rows[0]["Users"]) == true)
{
Session["UserID"] = dt.Rows[0]["UserID"].ToString();
Response.Redirect("Users.aspx", false);
}
else
{
Session["UserID"] = "";
Response.Redirect("Login.aspx", false);
}
}
else
{
lblError.Text = "You don't have permission to view this Site!";
Session["UserID"] = "";
}*/
}
}
推荐答案
Response.Redirect("Home.aspx", true);
尝试将true作为第二个参数传递。当您重定向到新页面时会发生这种情况,并且会发生异常,询问是否应该停止执行当前请求。
try passing true as second parameter. this happens when you redirect to new page and exception occurs asking whether execution of current request should be stopped.
这篇关于登录问题,显示错误页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文