登录并重定向到可选页面 [英] LogIn And Redirect to optional Pages
本文介绍了登录并重定向到可选页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
Session["CustomerLogin"] = "CustomerLogin";
Session["CustomerLogin"] = txtUsername.Text;
if(Session["txtRoles"] == "Cust")
Response.Redirect("~/home.aspx");
else if(Session["txtRoles"] == "Admin")
Response.Redirect("~/homeAdmin.aspx");
-------
此代码位于LogIn按钮下。我希望它允许用户根据他/她的详细信息登录页面。
没有显示错误但是当我尝试登录时它没有不允许用户。
什么是Problam?
-------
this code is under LogIn button. I want it to allow a User to Log In to a page according to his/her details.
no error is shown but when i am trying to log in it doesn't allow the user to.
Whats The Problam?
推荐答案
if(Session["Name1"]=="value1")
{
Response.Redirect("Page1.aspx");
}
else if(Session["Name2"]=="Value2")
{
Response.Redirect("Page1.aspx");
}
protected void btnLogin_Click(object sender,EventArgs e)
{
试试
{
if(check())
{
Sessio [CustomerLogin] = CustomerLogin;
会话[CustomerLoginName] = txtUsername.Text;
if(Session [txtRoles] == Cust)
{
Response.Redirect(~home.aspx);
}
else if(Session [txtRoles] == Admin)
{
Response.Redirect(~categics.aspx);
}
}
else
{
errorDV.Visible = true;
txtUsername.Focus();
}
if( txtUsername.Text.Length == 0 txtPassword.Text.Length == 0)
{
errorDV.Visible = true;
txtUsername.Focus();
}
}
catch
{
errorDV.Visible = true;
txtUsername.Focus();
}
}
私人布尔检查()
{
SqlConnection con = new SqlConnection(strConnString);
con .Open();
SqlCommand com = new SqlCommand(从Customer中选择count(),其中Username = @ uname,Password = @upass和Roles = @urole,con);
com.Parameters.Add(@ uname,SqlDbType.VarChar).Value = txtUsername.Text;
com.Parameters.Add(@ upass,SqlDbType.VarChar).Value = MD6Result(txtPassword。文字);
com.Parameters.Add(@urole,SqlDbType.VarChar).Value = txtRoles.Text;
if(com.ExecuteScalar()。ToString()== 1)
返回true;
con.Close( );
返回false;
}
私有字符串MD6Result(字符串输入)
{
string str = MD5Result(输入)+ SmartAccessoriesInc;
返回MD5Result(str);
}
私有字符串MD5Result(字符串输入)
{
MD5 x =新MD5CryptoServiceProvider();
byte [] lam =编码。 UTF8.GetBytes(输入);
lam = x.ComputeHash(lam);
StringBuilder s = new StringBuilder();
foreach( lam中的字节b)
{
s.Append(b.ToString(x2).ToLower());
}
返回s.ToString();
}
---------------------
这是本守则的其余部分。
请帮忙
protected void btnLogin_Click(object sender, EventArgs e)
{
try
{
if (check())
{
Sessio[CustomerLogin] = CustomerLogin;
Session[CustomerLoginName] = txtUsername.Text;
if (Session[txtRoles] == Cust)
{
Response.Redirect(~home.aspx);
}
else if (Session[txtRoles] == Admin)
{
Response.Redirect(~categories.aspx);
}
}
else
{
errorDV.Visible = true;
txtUsername.Focus();
}
if (txtUsername.Text.Length == 0 txtPassword.Text.Length == 0)
{
errorDV.Visible = true;
txtUsername.Focus();
}
}
catch
{
errorDV.Visible = true;
txtUsername.Focus();
}
}
private bool check()
{
SqlConnection con = new SqlConnection(strConnString);
con.Open();
SqlCommand com = new SqlCommand(select count() from Customer where Username = @uname ,Password = @upass and Roles = @urole, con);
com.Parameters.Add(@uname, SqlDbType.VarChar).Value = txtUsername.Text;
com.Parameters.Add(@upass, SqlDbType.VarChar).Value = MD6Result(txtPassword.Text);
com.Parameters.Add(@urole, SqlDbType.VarChar).Value = txtRoles.Text;
if (com.ExecuteScalar().ToString() == 1)
return true;
con.Close();
return false;
}
private string MD6Result(string input)
{
string str = MD5Result(input) + SmartAccessoriesInc;
return MD5Result(str);
}
private string MD5Result(string input)
{
MD5 x = new MD5CryptoServiceProvider();
byte[] lam = Encoding.UTF8.GetBytes(input);
lam = x.ComputeHash(lam);
StringBuilder s = new StringBuilder();
foreach (byte b in lam)
{
s.Append(b.ToString(x2).ToLower());
}
return s.ToString();
}
---------------------
This is the rest of the Code.
Please help out
这篇关于登录并重定向到可选页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文