登录页面未正确重定向 [英] Login Page not getting redirected properly
本文介绍了登录页面未正确重定向的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
protected void btnSubmit_Click(object sender, EventArgs e)
{
SqlDataReader sdrDatanew = null; //Read rows one by one.
string strnew;
string connectionString = WebConfigurationManager.ConnectionStrings["Gen_LicConnectionString"].ConnectionString; //Define new connectionstring
SqlConnection connew = new SqlConnection(connectionString); //establishes a new sql connection
connew.Open(); //Opens Connection
strnew = "select User_Type from User_Details where User_Type='" + ddlUserSel.SelectedItem.Value + "' AND LoginID = '" + txtUserName.Text + "' AND Password = '" + txtPassword.Text + "'";
SqlCommand sqlCommnew = new SqlCommand(strnew, connew); //passes the command and connection
sdrDatanew = sqlCommnew.ExecuteReader(); //For select command
int userType = 0;
if (sdrDatanew.HasRows)
{
if (sdrDatanew.Read())
{
userType = Convert.ToInt32(sdrDatanew["User_Type"].ToString());
}
}
switch (userType)
{
case 0:
Response.Redirect("Lic_Gen.aspx");
break;
case 1:
Response.Redirect("Cust_Page.aspx");
break;
default:
lblDisp.Text= "Invalid User/Password";
break;
}
connew.Close();
}
我在重定向页面时遇到问题。无论密码或用户ID是否错误,甚至选择客户或任何东西,对于所有内容,页面都会被重定向到Lic_gen.aspx页面。我知道我已经明确地将usertype定义为0,但我并没有真正得到如何解决这个错误。
有人可以帮助我。
I''m having issues in redirecting my page. Irrespective of wrong password or user id, or even choosing customer or anything, for everything, the page gets redirected to the "Lic_gen.aspx" page. I know i''ve explicitly defined "usertype" as 0, but I''m not really getting how to resolve this error.
Can someone help me please.
推荐答案
这是因为userType变量初始化为值0.我不确定sdrDatanew [User_Type]返回的所有其他值是什么。
你最初可以将userType值初始化为其他一些值,如Int32.MinValue,然后试试。
This is because userType variable is initialized to value 0. I am not sure what all other values sdrDatanew["User_Type"] returns.
You can initialize userType value initially to some other value like Int32.MinValue and then try out.
我不确定,可能是你的查询没有返回行。因此你初始化了userType = 0
,它转到了案例0:
所以,试试调试你的代码。
I am not sure, may be your query is not returning rows. and hence you have initializeduserType=0
, its going to the case 0:
So, try debugging your code.
您好,
请优化您的选择查询,例如
Hi,
Please optimise your select query like
select User_Type from User_Details where LoginID = ''" + txtUserName.Text + "'' AND Password = ''" + txtPassword.Text + "''"
再试一次。
谢谢
And try again.
Thanks
这篇关于登录页面未正确重定向的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文